ajaxpost带参数请求后台怎么接收参数?
把要发送的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; }