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

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

时间:2019-05-08 12:13:41

相关推荐

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; }

如果觉得《ajaxpost带参数请求后台怎么接收参数 – Ajax – 前端》对你有帮助,请点赞、收藏,并留下你的观点哦!

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