当前位置: 首页>>代码示例>>Java>>正文


Java Request.body方法代码示例

本文整理汇总了Java中com.squareup.okhttp.Request.body方法的典型用法代码示例。如果您正苦于以下问题:Java Request.body方法的具体用法?Java Request.body怎么用?Java Request.body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.Request的用法示例。


在下文中一共展示了Request.body方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: matches

import com.squareup.okhttp.Request; //导入方法依赖的package包/类
@Override
public boolean matches(Request right) {
  if (!right.url().equals(left.url())) {
    return false;
  }
  if (!right.method().equals(left.method())) {
    return false;
  }
  if (!right.headers().toMultimap().equals(left.headers().toMultimap())) {
    return false;
  }
  if (right.body() == null && left.body() == null) {
    return true;
  } else if (right.body() != null && left.body() != null) {
    try {
      return right.body().contentLength() == left.body().contentLength();
    } catch (IOException e) {
      return false;
    }
  } else {
    return false;
  }
}
 
开发者ID:honnix,项目名称:rkt-launcher,代码行数:24,代码来源:ClientTest.java

示例2: intercept

import com.squareup.okhttp.Request; //导入方法依赖的package包/类
@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    Response response = null;
    try {
        Log.i(TAG, "request is: \n" + request.toString());
        Log.i(TAG, "request headers are: \n" + request.headers().toString());
        Buffer buffer = new Buffer();
        if (request.body() != null) {
            request.body().writeTo(buffer);
        }
        String bodyStr = buffer.readUtf8();
        Log.i(TAG, "REQUEST body is: \n" + bodyStr);
        response = chain.proceed(request);
        String responseBodyString = "";
        MediaType type = null;
        if (response.body() != null) {
            type = response.body().contentType();
            responseBodyString = response.body().string();
        }
        response = response.newBuilder().body(ResponseBody.create(type, responseBodyString.getBytes())).build();
        Log.i(TAG, "RESPONSE body is \n" + responseBodyString);
        return response;
    } catch (Exception e) {
        Log.e(TAG, "RequestInterceptor: intercept", e);
    }
    return response;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:29,代码来源:RestClient.java

示例3: proceed

import com.squareup.okhttp.Request; //导入方法依赖的package包/类
public Response proceed(Request request) throws IOException {
    this.calls++;
    if (this.index > 0) {
        Interceptor caller = (Interceptor) this.this$0.client.networkInterceptors().get(this
                .index - 1);
        Address address = connection().getRoute().getAddress();
        if (!request.httpUrl().host().equals(address.getUriHost()) || request.httpUrl().port
                () != address.getUriPort()) {
            throw new IllegalStateException("network interceptor " + caller + " must retain " +
                    "the same host and port");
        } else if (this.calls > 1) {
            throw new IllegalStateException("network interceptor " + caller + " must call " +
                    "proceed() exactly once");
        }
    }
    if (this.index < this.this$0.client.networkInterceptors().size()) {
        HttpEngine$NetworkInterceptorChain chain = new HttpEngine$NetworkInterceptorChain
                (this.this$0, this.index + 1, request);
        Interceptor interceptor = (Interceptor) this.this$0.client.networkInterceptors().get
                (this.index);
        Response intercept = interceptor.intercept(chain);
        if (chain.calls != 1) {
            throw new IllegalStateException("network interceptor " + interceptor + " must " +
                    "call proceed() exactly once");
        } else if (intercept != null) {
            return intercept;
        } else {
            throw new NullPointerException("network interceptor " + interceptor + " returned " +
                    "null");
        }
    }
    HttpEngine.access$000(this.this$0).writeRequestHeaders(request);
    HttpEngine.access$102(this.this$0, request);
    if (this.this$0.permitsRequestBody(request) && request.body() != null) {
        BufferedSink bufferedRequestBody = Okio.buffer(HttpEngine.access$000(this.this$0)
                .createRequestBody(request, request.body().contentLength()));
        request.body().writeTo(bufferedRequestBody);
        bufferedRequestBody.close();
    }
    Response response = HttpEngine.access$200(this.this$0);
    int code = response.code();
    if ((code != 204 && code != 205) || response.body().contentLength() <= 0) {
        return response;
    }
    throw new ProtocolException("HTTP " + code + " had non-zero Content-Length: " + response.body().contentLength());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:47,代码来源:HttpEngine$NetworkInterceptorChain.java


注:本文中的com.squareup.okhttp.Request.body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。