httpclient post 传参数
2018-07-20 来源:open-open
httpclient post 参数
public static void main(String args[]) throws IOException { CloseableHttpClient client = HttpClients.createDefault(); String url = "http://localhost:8888/QueryUser"; HttpPost post = new HttpPost(url); String name= "mike"; JSONObject arg = new JSONObject().element("age", 44).element("job", "cooker")); String queryCase = "name=" + name+ "&&arg=" + arg; StringEntity reqEntity = new StringEntity(queryCase); System.out.println(reqEntity); reqEntity.setContentType("application/x-www-form-urlencoded"); post.setEntity(reqEntity); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String message = EntityUtils.toString(entity, "utf-8"); System.out.println(message); } else { System.out.println("请求失败"); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:PHP获取POST数据的三种方法
最新资讯
热门推荐