回覆列表
  • 1 # 使用者7958542670337

    把要傳送的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; }

  • 中秋節和大豐收的關聯?
  • 隔夜的涼開水有毒嗎?起床後到底能不能喝隔夜的涼開水?