/**
* 推送body数据,post接口
* @param url
* @param params
* @param token
* @return
*/
public static JSONObject doBodyPost(String url, JSONObject params,String token) {
try {
//设置 http头 Content-Type 的值
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(params.toString(),JSON);
Request request = new Request.Builder()
.header("X-66nao-Auth-T",token)
.post(body)
.url(url).build();
Response response = OkHttpUtil.getInstance().newCall(request).execute();
if (response.isSuccessful()) {
String content = response.body().string();
//System.out.println("response:"+content);
if (ObjectUtil.isNotEmpty(content)) {
JSONObject jsonObject = JSONObject.parseObject(content);
return jsonObject;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
OKHttp3请求http接口传参body
最新推荐文章于 2024-06-05 11:14:36 发布