mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 03:46:50 +08:00
请求头指定编码
This commit is contained in:
@@ -7,6 +7,8 @@ import org.apache.http.entity.StringEntity;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author
|
* @author
|
||||||
* @date 2025年11月18日
|
* @date 2025年11月18日
|
||||||
@@ -22,8 +24,9 @@ public class HttpUtils {
|
|||||||
// POST 请求
|
// POST 请求
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
//HttpPost httpPost = new HttpPost("https://jsonplaceholder.typicode.com/posts");
|
//HttpPost httpPost = new HttpPost("https://jsonplaceholder.typicode.com/posts");
|
||||||
httpPost.setEntity(new StringEntity(message));
|
httpPost.setEntity(new StringEntity(message, StandardCharsets.UTF_8));
|
||||||
httpPost.setHeader("Content-Type", "application/json");
|
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||||
|
httpPost.setHeader("Accept", "application/json");
|
||||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
log.info("---------------发送消息响应 -------{}",response);
|
log.info("---------------发送消息响应 -------{}",response);
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
Reference in New Issue
Block a user