RequestBody . RequestBody, post. - , , , . , , , POST. , . , , , URL, .
class AddPostParamRequestBody extends RequestBody {
final RequestBody body;
final String parameter;
AddPostParamRequestBody(RequestBody body, String name, String value) {
this.body = body;
this.parameter = "&" + name + "=" + value;
}
@Override
public long contentLength() throws IOException {
return body.contentLength() + parameter.length();
}
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public void writeTo(BufferedSink bufferedSink) throws IOException {
body.writeTo(bufferedSink);
bufferedSink.writeString(parameter, Charset.forName("UTF-8"));
}
}
-
client.interceptors().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
HttpUrl url = request.httpUrl().newBuilder().addQueryParameter("added", "param").build();
AddPostParamRequestBody newBody = new AddPostParamRequestBody(request.body(), "sUserKey","3254345kdskf");
Request newRequest = request.newBuilder().post(newBody).url(url).build();
return chain.proceed(newRequest);
}
});
, Field , , .