2024年2月27日发(作者:)
CloseableHttpClient httpclient = ().build(); HttpPost post = null; String resData = null; CloseableHttpResponse result = null; try { post = new HttpPost(url); HttpEntity entity2 = new StringEntity(body, _8); fig(().setConnectTimeout(30000).setSocketTimeout(30000).build()); der("Content-Type", "application/json"); der("Access-Token", "sund2f3bf3e7ecea902bcdb7027e9139a02"); ity(entity2); result = e(post); if (_OK == tusLine().getStatusCode()) { resData = ng(ity()); } } finally { if (result != null) { (); } if (post != null) { eConnection(); } (); } return resData; }
/** * HttpPost发送header,Content(json格式) *
* @param url * @param json * @param headers * @return */ public static String post(String url, Map
HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); ("请求地址:" + url); // der("Content-Type", "application/x-www-form-urlencoded"); ("请求头信息:" + headers); if (headers != null) { Set
} String charset = null; try { StringEntity s = new StringEntity(ng(), "utf-8"); ("请求json参数:" + jsonMap); // tentEncoding(new BasicHeader(T_TYPE, "application/json")); // tentType("application/json"); // tentType(new BasicHeader(T_TYPE, "application/json")); ity(s);
("请求实体数据:" + post);
("请求实体数据:" + post); // HttpResponse res = e(post); HttpResponse httpResponse = e(post); InputStream inStream = ity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "utf-8")); StringBuilder strber = new StringBuilder();
String line = null; while ((line = ne()) != null) (line + "n"); (); ("MobilpriseActivity:" + strber);
if (tusLine().getStatusCode() == _OK) { HttpEntity entity = ity(); charset = tentCharSet(entity); } } catch (Exception e) { ("报错咯:" + sage()); throw new RuntimeException(e); } ("响应参数:" + charset); return charset; }
public static void main(String[] args) { try { Map
("系统错误:",e); }
}
} // 设置请求参数 Map


发布评论