本文整理匯總了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);
}
示例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;
}
示例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));
}
示例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());
}
示例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);
}
示例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);
}