okhttp3 post 数据打包方法

import okhttp3.OkHttpClient;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody; // HashMap with Params
HashMap<String, String> params = new HashMap<>();
params.put( "Param1", "A" );
params.put( "Param2", "B" ); // Initialize Builder (not RequestBody)
FormBody.Builder builder = new FormBody.Builder(); // Add Params to Builder
for ( Map.Entry<String, String> entry : params.entrySet() ) {
builder.add( entry.getKey(), entry.getValue() );
} // Create RequestBody
RequestBody formBody = builder.build(); // Create Request (same)
Request request = new Request.Builder()
.url( "url" )
.post( formBody )
.build();
上一篇:Modbus CRC 16 (C#)


下一篇:golang高并发的理解