import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class HttpUtils {
private static String charset = "utf-8";
public static String sendPost (String url, String json) throws ClientProtocolException, IOException{
HttpPost httpPost = new HttpPost(url);
CloseableHttpClient client = HttpClients.createDefault();
StringEntity entity = new StringEntity(json, charset);//解决中文
HttpUtil工具类发送post请求
最新推荐文章于 2024-09-28 14:02:21 发布
该博客介绍了如何使用HttpUtils工具类发送POST请求。通过创建HttpPost对象,设置URL和JSON参数,利用CloseableHttpClient发送请求,并处理响应,确保中文内容正常显示。
摘要由CSDN通过智能技术生成