首页 > 编程语言 >Java发送HttpPost请求

Java发送HttpPost请求

时间:2023-01-11 20:11:26浏览次数:40  
标签:Java 请求 UTF 发送 application json HttpPost postMethod new

依赖jar包

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.6</version>
</dependency>

发送请求

HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod("https://xxx/xxxx");
postMethod.addRequestHeader("content-type", "application/json;charset=UTF-8");
postMethod.addRequestHeader("accept", "application/json;charset=UTF-8");

//添加请求参数
postMethod.setRequestEntity(new StringRequestEntity(dataObj.toString(), "application/json", "UTF-8"));
httpClient.executeMethod(postMethod);
String result = postMethod.getResponseBodyAsString();

标签:Java,请求,UTF,发送,application,json,HttpPost,postMethod,new
From: https://www.cnblogs.com/zhang-han/p/17044785.html

相关文章