okhttp3 - How to send post parameters dynamically (or in loop) in OKHTTP 3.x in android? -


i using okhttp 3.x version. want post multiple parameters , add params in loop. know in version 2.x , can use formencodingbuilder , add params in loop , create request body. in 3.x , class has been removed.

here current code :

requestbody formbody = new formbody.builder()             .add("param1", value1)             .add("param2", value2)             .build(); request request = new request.builder()             .url("url")             .post(formbody)             .build(); 

now want add 5 params in loop i.e create request body building formbody in loop. wrote above, know how in okhttp version 2.x using version 3.x.

any or guidance appreciated.

thanks in advance

here's how it:

formbody.builder formbuilder = new formbody.builder()         .add("key", "123");  // dynamically add more parameter this: formbuilder.add("phone", "000000");  requestbody formbody = formbuilder.build();  request request = new request.builder()                 .url("https://aaa.com")                 .post(formbody)                 .build(); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -