okhttp发送post请求

String url = "http://www.xxx.com/api/test";


OkHttpClient httpClient = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json;charset=UTF-8");

String post = "{\"test\":123}";


RequestBody requestBody = RequestBody.create(mediaType, post);


Request request = new Request.Builder()
.post(requestBody)
.url(url)
.build();

Response response = httpClient.newCall(request).execute();
posted @ 2018-08-21 10:22  范世强  阅读(6756)  评论(0编辑  收藏  举报