當前位置: 首頁>>代碼示例>>Java>>正文


Java MockWebServer.useHttps方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.mockwebserver.MockWebServer.useHttps方法的典型用法代碼示例。如果您正苦於以下問題:Java MockWebServer.useHttps方法的具體用法?Java MockWebServer.useHttps怎麽用?Java MockWebServer.useHttps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.mockwebserver.MockWebServer的用法示例。


在下文中一共展示了MockWebServer.useHttps方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: redirectedFromHttpToHttpsFollowingProtocolRedirects

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Test public void redirectedFromHttpToHttpsFollowingProtocolRedirects() throws Exception {
  server2 = new MockWebServer();
  server2.useHttps(sslContext.getSocketFactory(), false);
  server2.enqueue(new MockResponse().setBody("This is secure HTTPS!"));
  server2.play();

  server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
      .addHeader("Location: " + server2.getUrl("/"))
      .setBody("This page has moved!"));
  server.play();

  client.setSslSocketFactory(sslContext.getSocketFactory());
  client.setHostnameVerifier(new RecordingHostnameVerifier());
  client.setFollowProtocolRedirects(true);
  connection = client.open(server.getUrl("/"));
  assertContent("This is secure HTTPS!", connection);
  assertFalse(connection instanceof HttpsURLConnection);
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:19,代碼來源:URLConnectionTest.java

示例2: startServer

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
private MockWebServer startServer() throws IOException {
  Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
  MockWebServer server = new MockWebServer();

  if (tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    server.useHttps(sslContext.getSocketFactory(), false);
    server.setNpnEnabled(true);
    server.setNpnProtocols(protocols);
  }

  final MockResponse response = newResponse();
  server.setDispatcher(new Dispatcher() {
    @Override public MockResponse dispatch(RecordedRequest request) {
      return response;
    }
  });

  server.play();
  return server;
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:22,代碼來源:Benchmark.java

示例3: run

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public void run() throws IOException {
    MockWebServer server = new MockWebServer();
    server.useHttps(sslContext.getSocketFactory(), false);
    server.setDispatcher(this);
    InetAddress address = HttpUtil.getHostAddress();
    server.start(address,port);
    System.out.println(String.format("Started server for: http://%s:%d/", address.getHostAddress(), port));
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:9,代碼來源:SampleServer.java

示例4: redirectToAnotherOriginServer

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
private void redirectToAnotherOriginServer(boolean https) throws Exception {
  server2 = new MockWebServer();
  if (https) {
    server.useHttps(sslContext.getSocketFactory(), false);
    server2.useHttps(sslContext.getSocketFactory(), false);
    server2.setNpnEnabled(false);
    client.setSslSocketFactory(sslContext.getSocketFactory());
    client.setHostnameVerifier(new RecordingHostnameVerifier());
  }

  server2.enqueue(new MockResponse().setBody("This is the 2nd server!"));
  server2.enqueue(new MockResponse().setBody("This is the 2nd server, again!"));
  server2.play();

  server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
      .addHeader("Location: " + server2.getUrl("/").toString())
      .setBody("This page has moved!"));
  server.enqueue(new MockResponse().setBody("This is the first server again!"));
  server.play();

  connection = client.open(server.getUrl("/"));
  assertContent("This is the 2nd server!", connection);
  assertEquals(server2.getUrl("/"), connection.getURL());

  // make sure the first server was careful to recycle the connection
  assertContent("This is the first server again!", client.open(server.getUrl("/")));
  assertContent("This is the 2nd server, again!", client.open(server2.getUrl("/")));

  String server1Host = hostName + ":" + server.getPort();
  String server2Host = hostName + ":" + server2.getPort();
  assertContains(server.takeRequest().getHeaders(), "Host: " + server1Host);
  assertContains(server2.takeRequest().getHeaders(), "Host: " + server2Host);
  assertEquals("Expected connection reuse", 1, server.takeRequest().getSequenceNumber());
  assertEquals("Expected connection reuse", 1, server2.takeRequest().getSequenceNumber());
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:36,代碼來源:URLConnectionTest.java

示例5: setUp

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
private void setUp(int poolSize) throws Exception {
  SocketFactory socketFactory = SocketFactory.getDefault();

  spdyServer = new MockWebServer();
  httpServer = new MockWebServer();
  spdyServer.useHttps(sslContext.getSocketFactory(), false);

  httpServer.play();
  httpAddress = new Address(httpServer.getHostName(), httpServer.getPort(), socketFactory, null,
      null, HttpAuthenticator.SYSTEM_DEFAULT, null, Protocol.SPDY3_AND_HTTP11);
  httpSocketAddress = new InetSocketAddress(InetAddress.getByName(httpServer.getHostName()),
      httpServer.getPort());

  spdyServer.play();
  spdyAddress = new Address(spdyServer.getHostName(), spdyServer.getPort(), socketFactory,
      sslContext.getSocketFactory(), new RecordingHostnameVerifier(),
      HttpAuthenticator.SYSTEM_DEFAULT, null,Protocol.SPDY3_AND_HTTP11);
  spdySocketAddress = new InetSocketAddress(InetAddress.getByName(spdyServer.getHostName()),
      spdyServer.getPort());

  Route httpRoute = new Route(httpAddress, Proxy.NO_PROXY, httpSocketAddress, true);
  Route spdyRoute = new Route(spdyAddress, Proxy.NO_PROXY, spdySocketAddress, true);
  pool = new ConnectionPool(poolSize, KEEP_ALIVE_DURATION_MS);
  httpA = new Connection(pool, httpRoute);
  httpA.connect(200, 200, null);
  httpB = new Connection(pool, httpRoute);
  httpB.connect(200, 200, null);
  httpC = new Connection(pool, httpRoute);
  httpC.connect(200, 200, null);
  httpD = new Connection(pool, httpRoute);
  httpD.connect(200, 200, null);
  httpE = new Connection(pool, httpRoute);
  httpE.connect(200, 200, null);
  spdyA = new Connection(pool, spdyRoute);
  spdyA.connect(20000, 20000, null);

  owner = new Object();
  httpA.setOwner(owner);
  httpB.setOwner(owner);
  httpC.setOwner(owner);
  httpD.setOwner(owner);
  httpE.setOwner(owner);
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:44,代碼來源:ConnectionPoolTest.java

示例6: run

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public void run() throws IOException {
  MockWebServer server = new MockWebServer();
  server.useHttps(sslContext.getSocketFactory(), false);
  server.setDispatcher(this);
  server.play(port);
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:7,代碼來源:SampleServer.java


注:本文中的com.squareup.okhttp.mockwebserver.MockWebServer.useHttps方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。