2

I want to change the RequestBody in Okhttp, the RequestBody's method is POST form.

But, I don't know how to change the RequestBody to a Form or map.(Which //TODO in the follow)

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);
        }
    });
Pitty
  • 329
  • 4
  • 15
  • Does FormBody.Builder work? http://square.github.io/okhttp/3.x/okhttp/index.html?okhttp3/FormBody.Builder.html – Jesse Wilson Jan 05 '16 at 04:35
  • I used 2.x, and want to change the origin RequestBody to a map, then change some in the map, not create a new RequestBody. I don't know how to pick out the key and value from a RequestBody Object. – Pitty Jan 05 '16 at 05:25

1 Answers1

0

This question might have been replied to already. Please check the answer

The suggestion is to create a new FormBody and convert it to text, and concatenate with the existing form, also converted to text, then submit.

n002213f
  • 7,805
  • 13
  • 69
  • 105