okhttp3.mockwebserver.MockWebServer.useHttps()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中okhttp3.mockwebserver.MockWebServer.useHttps()方法的一些代码示例,展示了MockWebServer.useHttps()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.useHttps()方法的具体详情如下:
包路径:okhttp3.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:useHttps

MockWebServer.useHttps介绍

[英]Serve requests with HTTPS rather than otherwise.
[中]

代码示例

代码示例来源:origin: square/okhttp

public void run() throws IOException {
 MockWebServer server = new MockWebServer();
 server.useHttps(sslContext.getSocketFactory(), false);
 server.setDispatcher(this);
 server.start(port);
}

代码示例来源:origin: square/okhttp

public void run() throws Exception {
 String localhost = InetAddress.getByName("localhost").getCanonicalHostName();
 HeldCertificate localhostCertificate = new HeldCertificate.Builder()
   .addSubjectAlternativeName(localhost)
   .build();
 HandshakeCertificates serverCertificates = new HandshakeCertificates.Builder()
   .heldCertificate(localhostCertificate)
   .build();
 MockWebServer server = new MockWebServer();
 server.useHttps(serverCertificates.sslSocketFactory(), false);
 server.enqueue(new MockResponse());
 HandshakeCertificates clientCertificates = new HandshakeCertificates.Builder()
   .addTrustedCertificate(localhostCertificate.certificate())
   .build();
 OkHttpClient client = new OkHttpClient.Builder()
   .sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager())
   .build();
 Call call = client.newCall(new Request.Builder()
   .url(server.url("/"))
   .build());
 Response response = call.execute();
 System.out.println(response.handshake().tlsVersion());
}

代码示例来源:origin: fabric8io/mockwebserver

private void startInternal() {
 if (initialized.compareAndSet(false, true)) {
  if (useHttps) {
   server.useHttps(MockSSLContextFactory.create().getSocketFactory(), false);
  }
  onStart();
 }
}

代码示例来源:origin: stackoverflow.com

MockWebServer serverForHttps = new MockWebServer();
serverForHttps .useHttps(SslContextBuilder.localhost().getSocketFactory(), false);
serverForHttps .start()

代码示例来源:origin: xjdr/xio

public static MockWebServer getSslMockWebServer(KeyManager[] keyManagers) throws Exception {
  MockWebServer server = new MockWebServer();
  server.useHttps(
    OkHttpUnsafe.getUnsafeSSLSocketFactory(keyManagers, unsafeTrustManager()), false);
  return server;
 }
}

代码示例来源:origin: cloudant/java-cloudant

@BeforeEach
public void beforeEach() {
  server = mockWebServerExt.get();
  server.useHttps(MockWebServerResources.getSSLSocketFactory(), false);
}

代码示例来源:origin: cloudant/java-cloudant

/**
 * Enables https on the mock web server receiving our requests if useHttpsServer is true.
 *
 * @throws Exception
 */
@BeforeEach
public void setupMockServerSSLIfNeeded(final boolean okUsable,
                    final boolean useSecureProxy,
                    final boolean useHttpsServer,
                    final boolean useProxyAuth) throws Exception {
  server = serverExt.get();
  if (useHttpsServer) {
    server.useHttps(MockWebServerResources.getSSLSocketFactory(), false);
  }
}

代码示例来源:origin: cloudant/java-cloudant

@BeforeEach
public void beforeEach() {
  server = mockWebServerExt.get();
  server.useHttps(MockWebServerResources.getSSLSocketFactory(), false);
  mockServerHostPort = String.format("%s:%s/", server.getHostName(), server.getPort());
  //setup mock IAM server
  mockIamServer = mockIamServerExt.get();
  iamSystemPropertyMock.setMockIamTokenEndpointUrl(mockIamServer.url(iamTokenEndpoint)
      .toString());
}

相关文章