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