1. 首页
  2. 服务器应用
  3. Web服务器
  4. SpringBoot使用httpclient发送Post请求的注意事项和示例代码

SpringBoot使用httpclient发送Post请求的注意事项和示例代码

上传者: 2023-07-06 08:49:46上传 TXT文件 885B 热度 39次

public static String post(String url, String params){ log.info("post url:" + url + " params:" + params); String responseStr = ""; try(CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(url); StringEntity stringEntity = new StringEntity(params, Charset.forName("UTF-8")); httpPost.setHeader("Content-type", "application/json"); httpPost.setEntity(stringEntity); Closeable

用户评论