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