/**
* @param url 请求的http地址
* @param sendJs 要发送的数据
* @return 响应数据
* @throws ParseException
* @throws IOException
*/
public static String sendHttpPost(String url, JSONObject sendJs) throws ParseException, IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
StringEntity entityParams = new StringEntity(sendJs.toJSONString(), "utf-8");
httpPost.setEntity(entityParams);
HttpResponse httpResponse;
httpResponse = httpClient.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
String resData = EntityUtils.toString(entity);
return resData;
}
java向某地址发送http的POST请求的示例
最新推荐文章于 2024-10-02 17:32:16 发布
本文将展示如何使用Java发送HTTP POST请求到指定URL。通过Java的HttpURLConnection或HttpClient库,可以轻松完成此操作,包括设置请求头和发送JSON或表单数据。详细步骤和示例代码将帮助开发者理解并应用到实际项目中。
2353

被折叠的 条评论
为什么被折叠?



