okhttp3.Request.method()方法的使用及代码示例

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

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

Request.method介绍

暂无

代码示例

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

@Override
public String getRequestMethod() {
 return request.method();
}

代码示例来源:origin: facebook/stetho

@Override
public String method() {
 return mRequest.method();
}

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

public boolean matches(Request request, Response response) {
 return url.equals(request.url().toString())
   && requestMethod.equals(request.method())
   && HttpHeaders.varyMatches(response, varyHeaders, request);
}

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

CacheHttpURLConnection(Response response) {
 super(response.request().url().url());
 this.request = response.request();
 this.response = response;
 // Configure URLConnection inherited fields.
 this.connected = true;
 this.doOutput = request.body() != null;
 this.doInput = true;
 this.useCaches = true;
 // Configure HttpUrlConnection inherited fields.
 this.method = request.method();
}

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

/**
 * Returns the request status line, like "GET / HTTP/1.1". This is exposed to the application by
 * {@link HttpURLConnection#getHeaderFields}, so it needs to be set even if the transport is
 * HTTP/2.
 */
public static String get(Request request, Proxy.Type proxyType) {
 StringBuilder result = new StringBuilder();
 result.append(request.method());
 result.append(' ');
 if (includeAuthorityInRequestLine(request, proxyType)) {
  result.append(request.url());
 } else {
  result.append(requestPath(request.url()));
 }
 result.append(" HTTP/1.1");
 return result.toString();
}

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

@Override public Response intercept(Chain chain) throws IOException {
 Request originalRequest = chain.request();
 if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
  return chain.proceed(originalRequest);
 }
 Request compressedRequest = originalRequest.newBuilder()
   .header("Content-Encoding", "gzip")
   .method(originalRequest.method(), gzip(originalRequest.body()))
   .build();
 return chain.proceed(compressedRequest);
}

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

/** Returns true if the response must have a (possibly 0-length) body. See RFC 7231. */
public static boolean hasBody(Response response) {
 // HEAD requests never yield a body regardless of the response headers.
 if (response.request().method().equals("HEAD")) {
  return false;
 }
 int responseCode = response.code();
 if ((responseCode < HTTP_CONTINUE || responseCode >= 200)
   && responseCode != HTTP_NO_CONTENT
   && responseCode != HTTP_NOT_MODIFIED) {
  return true;
 }
 // If the Content-Length or Transfer-Encoding headers disagree with the response code, the
 // response is malformed. For best compatibility, we honor the headers.
 if (contentLength(response) != -1
   || "chunked".equalsIgnoreCase(response.header("Transfer-Encoding"))) {
  return true;
 }
 return false;
}

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

OkHttpClient okClient = new OkHttpClient();
okClient.interceptors().add(new Interceptor() {
   @Override
   public Response intercept(Interceptor.Chain chain) throws IOException {
     Request original = chain.request();
     // Request customization: add request headers
     Request.Builder requestBuilder = original.newBuilder()
         .header("Authorization", token)
         .method(original.method(), original.body());
     Request request = requestBuilder.build();
     return chain.proceed(request);
   }
});

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

public RealWebSocket(Request request, WebSocketListener listener, Random random,
  long pingIntervalMillis) {
 if (!"GET".equals(request.method())) {
  throw new IllegalArgumentException("Request must be GET: " + request.method());
 }
 this.originalRequest = request;
 this.listener = listener;
 this.random = random;
 this.pingIntervalMillis = pingIntervalMillis;
 byte[] nonce = new byte[16];
 random.nextBytes(nonce);
 this.key = ByteString.of(nonce).base64();
 this.writerRunnable = () -> {
  try {
   while (writeOneFrame()) {
   }
  } catch (IOException e) {
   failWebSocket(e, null);
  }
 };
}

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

public boolean matches(Request request, Response response) {
 return url.equals(request.url().toString())
   && requestMethod.equals(request.method())
   && HttpHeaders.varyMatches(response, varyHeaders, request);
}

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

/**
  * Returns the {@link CacheResponse} from the delegate by converting the OkHttp {@link Request}
  * into the arguments required by the {@link ResponseCache}.
  */
 private CacheResponse getJavaCachedResponse(Request request) throws IOException {
  Map<String, List<String>> headers = JavaApiConverter.extractJavaHeaders(request);
  return delegate.get(request.url().uri(), request.method(), headers);
 }
}

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

OkHttpClient okClient = new OkHttpClient.Builder()
     .addInterceptor(
       new Interceptor() {
        @Override
        public Response intercept(Interceptor.Chain chain) throws IOException {
           Request original = chain.request();
           // Request customization: add request headers
           Request.Builder requestBuilder = original.newBuilder()
               .header("Authorization", token)
               .method(original.method(), original.body());
           Request request = requestBuilder.build();
           return chain.proceed(request);
         }
       })
     .build();

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

@Override public Response intercept(Chain chain) throws IOException {
  RealInterceptorChain realChain = (RealInterceptorChain) chain;
  Request request = realChain.request();
  StreamAllocation streamAllocation = realChain.streamAllocation();

  // We need the network to satisfy this request. Possibly for validating a conditional GET.
  boolean doExtensiveHealthChecks = !request.method().equals("GET");
  HttpCodec httpCodec = streamAllocation.newStream(client, chain, doExtensiveHealthChecks);
  RealConnection connection = streamAllocation.connection();

  return realChain.proceed(request, streamAllocation, httpCodec, connection);
 }
}

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

public static List<Header> http2HeadersList(Request request) {
 Headers headers = request.headers();
 List<Header> result = new ArrayList<>(headers.size() + 4);
 result.add(new Header(TARGET_METHOD, request.method()));
 result.add(new Header(TARGET_PATH, RequestLine.requestPath(request.url())));
 String host = request.header("Host");
 if (host != null) {
  result.add(new Header(TARGET_AUTHORITY, host)); // Optional.
 }
 result.add(new Header(TARGET_SCHEME, request.url().scheme()));
 for (int i = 0, size = headers.size(); i < size; i++) {
  // header names must be lowercase.
  String name = headers.name(i).toLowerCase(Locale.US);
  if (!HTTP_2_SKIPPED_REQUEST_HEADERS.contains(name)
    || name.equals(TE) && headers.value(i).equals("trailers")) {
   result.add(new Header(name, headers.value(i)));
  }
 }
 return result;
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public Response intercept(Chain chain) throws IOException {
  Request originalRequest = chain.request();
  if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
    return chain.proceed(originalRequest);
  }
  Request compressedRequest = originalRequest.newBuilder()
      .header("Content-Encoding", "gzip")
      .method(originalRequest.method(), forceContentLength(gzip(originalRequest.body())))
      .build();
  return chain.proceed(compressedRequest);
}

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

@Nullable CacheRequest put(Response response) {
 String requestMethod = response.request().method();
 if (HttpMethod.invalidatesCache(response.request().method())) {
  try {
   remove(response.request());

代码示例来源:origin: JessYanCoding/MVPArms

private static String[] getRequest(Request request) {
  String log;
  String header = request.headers().toString();
  log = METHOD_TAG + request.method() + DOUBLE_SEPARATOR +
      (isEmpty(header) ? "" : HEADERS_TAG + LINE_SEPARATOR + dotHeaders(header));
  return log.split(LINE_SEPARATOR);
}

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

@Override public Response intercept(Chain chain) throws IOException {
  RealInterceptorChain realChain = (RealInterceptorChain) chain;
  Request request = realChain.request();
  StreamAllocation streamAllocation = realChain.streamAllocation();

  // We need the network to satisfy this request. Possibly for validating a conditional GET.
  boolean doExtensiveHealthChecks = !request.method().equals("GET");
  HttpCodec httpCodec = streamAllocation.newStream(client, chain, doExtensiveHealthChecks);
  RealConnection connection = streamAllocation.connection();

  return realChain.proceed(request, streamAllocation, httpCodec, connection);
 }
}

相关文章