okhttp3.Response.handshake()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(141)

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

Response.handshake介绍

[英]Returns the TLS handshake of the connection that carried this response, or null if the response was received without TLS.
[中]返回承载此响应的连接的TLS握手,如果接收到的响应没有TLS,则返回null。

代码示例

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

@Override protected Handshake handshake() {
 return delegate.response.handshake();
}

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

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/helloworld.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.handshake().cipherSuite());
  System.out.println(response.body().string());
 }
}

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

@Override public void onResponse(Call call, Response response) {
 synchronized (lock) {
  this.response = response;
  this.handshake = response.handshake();
  this.url = response.request().url().url();
  lock.notifyAll();
 }
}

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

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/robots.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  for (Certificate certificate : response.handshake().peerCertificates()) {
   System.out.println(CertificatePinner.pin(certificate));
  }
 }
}

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

Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = HttpHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
 this.sentRequestMillis = response.sentRequestAtMillis();
 this.receivedResponseMillis = response.receivedResponseAtMillis();
}

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

private static void sendRequest(OkHttpClient client, String url) {
  System.out.printf("%-40s ", url);
  System.out.flush();

  System.out.println(Platform.get());

  Request request = new Request.Builder().url(url).build();

  try (Response response = client.newCall(request).execute()) {
   Handshake handshake = response.handshake();
   System.out.println(handshake.tlsVersion()
     + " "
     + handshake.cipherSuite()
     + " "
     + response.protocol()
     + " "
     + response.code
     + " "
     + response.body.bytes().length
     + "b");
  } catch (IOException ioe) {
   System.out.println(ioe.toString());
  }
 }
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = HttpHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
 this.sentRequestMillis = response.sentRequestAtMillis();
 this.receivedResponseMillis = response.receivedResponseAtMillis();
}

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

final ResponseBody body = response.body();
if (response.request().isHttps()) {
 final Handshake handshake = response.handshake();
 return new SecureCacheResponse() {
  @Override

代码示例来源:origin: apollographql/apollo-android

ResponseHeaderRecord(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = HttpHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
 this.sentRequestMillis = response.sentRequestAtMillis();
 this.receivedResponseMillis = response.receivedResponseAtMillis();
}

代码示例来源: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: apache/nifi

/**
 * Returns a Map of flowfile attributes from the response http headers. Multivalue headers are naively converted to comma separated strings.
 */
private Map<String, String> convertAttributesFromHeaders(URL url, Response responseHttp){
  // create a new hashmap to store the values from the connection
  Map<String, String> map = new HashMap<>();
  responseHttp.headers().names().forEach( (key) -> {
      if (key == null) {
        return;
      }
      List<String> values = responseHttp.headers().values(key);
      // we ignore any headers with no actual values (rare)
      if (values == null || values.isEmpty()) {
        return;
      }
      // create a comma separated string from the values, this is stored in the map
      String value = csv(values);
      // put the csv into the map
      map.put(key, value);
  });
  if (responseHttp.request().isHttps()) {
    Principal principal = responseHttp.handshake().peerPrincipal();
    if (principal != null) {
      map.put(REMOTE_DN, principal.getName());
    }
  }
  return map;
}

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

if (request.isHttps() && cacheResponse.handshake() == null) {
 return new CacheStrategy(request, null);

代码示例来源:origin: com.squareup.okhttp3/okhttp

if (request.isHttps() && cacheResponse.handshake() == null) {
 return new CacheStrategy(request, null);

代码示例来源:origin: com.squareup.okhttp3/okhttp-urlconnection

@Override public void onResponse(Call call, Response response) {
 synchronized (lock) {
  this.response = response;
  this.handshake = response.handshake();
  this.url = response.request().url().url();
  lock.notifyAll();
 }
}

代码示例来源:origin: huxq17/SwipeCardsView

public Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = OkHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
}

代码示例来源:origin: duzechao/OKHttpUtils

public Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = OkHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
}

代码示例来源:origin: huxq17/tractor

public Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = OkHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
}

代码示例来源:origin: com.github.ljun20160606/okhttp

Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = HttpHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
 this.sentRequestMillis = response.sentRequestAtMillis();
 this.receivedResponseMillis = response.receivedResponseAtMillis();
}

代码示例来源:origin: apache/servicemix-bundles

Entry(Response response) {
 this.url = response.request().url().toString();
 this.varyHeaders = HttpHeaders.varyHeaders(response);
 this.requestMethod = response.request().method();
 this.protocol = response.protocol();
 this.code = response.code();
 this.message = response.message();
 this.responseHeaders = response.headers();
 this.handshake = response.handshake();
 this.sentRequestMillis = response.sentRequestAtMillis();
 this.receivedResponseMillis = response.receivedResponseAtMillis();
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-ribbon

public OkHttpStatusCodeException(String serviceId, Response response, ResponseBody responseBody, URI uri) {
  super(serviceId, response.code(), response, uri);
  this.response = new Response.Builder().code(response.code()).message(response.message()).protocol(response.protocol())
      .request(response.request()).headers(response.headers()).handshake(response.handshake())
      .cacheResponse(response.cacheResponse()).networkResponse(response.networkResponse())
      .priorResponse(response.priorResponse()).sentRequestAtMillis(response.sentRequestAtMillis())
      .body(responseBody).build();
}

相关文章