2 largecatfish largecatfish 于 2017.09.04 16:18 提问

okHttp的 post请求参数问题

{
"body": "first page",
"action": "101",
"head": {
"reqTime": "2017-08-31 12:14:40",
"reqMd5No": "90FF76E3377CADF5C77BE1E9A59D91AB",
"reqAuthNo": "9XEHuFqAu6qaMO8R6F7VHg==",
"reqSerialNo": "8ca9f5a492a7458ba0c2079b270ffab213305149431",
"user": "13305149431",
"version": "01"
},
"actionArg": "101.01"
}

这是我要发给服务器的post参数 我不知道用okHttp如何封装 求解

3个回答

j550341130
j550341130   2017.09.04 17:06
     OkHttpUtils.post().url(url)
     .addParams("body", "first page")
     .addParams("head", Json.toJsonString(new JsonBean())); // 使用FastJson第三方库把对象解析成jsonString
     .build().execute(callback)

    private class JsonBean{
        String reqTime = "2017-08-31 12:14:40";
        String reqMd5No = "90FF76E3377CADF5C77BE1E9A59D91AB";
        // ...其他的
     }
qq_36975161
qq_36975161   2017.09.04 17:08
    OkHttpClient okHttpClient = new OkHttpClient();

    RequestBody body = new FormBody.Builder()
            .add("userName" , "yaoyazhe").add("password" , "123456").build();
    Request.Builder builder = new Request.Builder();
    Request build = builder.url(url + "login").post(body).build();
Small_Mouse0
Small_Mouse0   Ds   Rxr 2017.09.04 20:45
Csdn user default icon
上传中...
上传图片
插入图片