org.apache.http.client.methods.HttpPost的使用和坑

org.apache.http.client.methods.HttpPost的使用和坑

依赖的jar包:

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

如何使用org.apache.http.client.methods.HttpPost 发送请求体呢? 

httpPost.setHeader("Content-Type","application/json;charset=UTF-8");
                httpPost.setEntity(new StringEntity(json,Constant.CHARSET_UTF));

 注意:如果请求体是json,则一定要设置"Content-Type"

否则服务器无法读取到

 

猜你喜欢

转载自hw1287789687.iteye.com/blog/2346980