public class DoPost {
public JSONObject GetOrder(String url,JSONObject jsonObject){
String url2 = url;
String result = "";
JSONObject resJson = new JSONObject();
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(url2);
StringEntity entity = new StringEntity(jsonObject.toString(), "utf-8");//解决中文乱码问题
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");//设置文档类型
post.setEntity(entity);
try {
HttpResponse resultResponse = httpClient.execute(post);
if (resultResponse.getStatusLine().getStatusCode() == 200) {
String resData = EntityUtils.toString(resultResponse.getEntity());
resJson = JSON.parseObject(resData);
} else
post.abort();
} catch (ClientProtocolException e) {
e.printStackTrace();
result = e.getMessage().toString();
} catch (IOException e) {
e.printStackTrace();
result = e.getMessage().toString();
}
return resJson;
}
POST编程代码实现
最新推荐文章于 2020-03-12 10:08:33 发布