更改Okhttp RequestBody表单值

时间:2016-01-05 02:29:39

标签: android okhttp

我想在Okhttp中更改RequestBody,RequestBody的方法是POST表单。

但是,我不知道如何将RequestBody更改为表单或地图。(以下是// TODO)

httpClient.networkInterceptors().add(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request original = chain.request();

            RequestBody body = original.body();
            if (null != body) {
                //TODO Get the form data, encrypt the value of 'data', and add a param with version/1.0
                body = new EncryptRequestBody(body);
            }

            Request.Builder requestBuilder = original.newBuilder()
                 .method(original.method(), body);

            Request request = requestBuilder.build();
            return chain.proceed(request);
        }
    });

1 个答案:

答案 0 :(得分:0)

这个问题可能已经回复了。请查看answer

建议是创建一个新的FormBody并将其转换为文本,并与现有表单连接,也转换为文本,然后提交。