这种请求方式看起来还不错,精简:
OkHttpClient client = new OkHttpClient();
// 设置数据类型
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
// 传参
RequestBody body = RequestBody.create(mediaType, "message=测试okhttp");
Request request = new Request.Builder()
.url("http://ip:port/pay/thirdPayNotify.do")
.post(body)// post方式
.addHeader("content-type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "4fdcee09-89d5-a6e5-7b01-72d1dddd712b")
.build();
try {
// 执行请求
Response response = client.newCall(request).execute();
System.out.println(response.body().toString()) ;
} catch (IOException e) {
e.printStackTrace();
}
response.body().string()