httpclient 直接json请求
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpclient 直接json请求相关的知识,希望对你有一定的参考价值。
已有json请求参数
String url = "http://192.168.15.23:8180/ab_admin?action=policy_check"; CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); StringEntity entity = new StringEntity(param, "utf-8");//解决中文乱码问题 entity.setContentEncoding("UTF-8"); entity.setContentType("application/json"); httpPost.setEntity(entity); CloseableHttpResponse response = httpclient.execute(httpPost); String respContent = ""; if (response.getStatusLine().getStatusCode() == 200) { HttpEntity he = response.getEntity(); respContent = EntityUtils.toString(he, "UTF-8"); return respContent; }
以上是关于httpclient 直接json请求的主要内容,如果未能解决你的问题,请参考以下文章