100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > ajaxpost带参数请求后台怎么接收参数 – Ajax – 前端

ajaxpost带参数请求后台怎么接收参数 – Ajax – 前端

时间:2018-11-24 12:37:38

相关推荐

ajaxpost带参数请求后台怎么接收参数 – Ajax – 前端

把要发送的json作为字符串传入body即可public static String sendHttpPost(String url, String body) throws Exception { closeableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); httpPost.addHeader(“Content-Type”, “application/json”); httpPost.setEntity(new StringEntity(body)); CloseableHttpResponse response = httpClient.execute(httpPost); System.out.println(response.getStatusLine().getStatusCode() + “\n”);

HttpEntity entity = response.getEntity(); String responseContent = EntityUtils.toString(entity, “UTF-8”); System.out.println(responseContent);

response.close(); httpClient.close(); return responseContent; }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。