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 headers, Map jsonMap) {

HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); ("请求地址:" + url); // der("Content-Type", "application/x-www-form-urlencoded"); ("请求头信息:" + headers); if (headers != null) { Set keys = (); for ( entrdy : et()) { der((), ue()); //n("headers:" + () + ",值" + ue()); }

} 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 headmap = new HashMap(); ("Access-Token", "sund2f3bf3e7ecea902bcdb7027e9139a02"); Map paramap = new HashMap(); ("customerDeptId", "38"); ("postCode", "qqqq"); n(doPost("10.39.137.100/api/needs/getInfoByCondition",headmap,paramap)); //n(sendPostByJson("10.39.137.100/api/needs/getInfoByCondition","{"customerDeptId":38,"postCode":"qqqq"}")); } catch (Exception e) {

("系统错误:",e); }

}

} // 设置请求参数 Map param = new HashMap(); ("test", "test"); // 设置请求头信息 Map headMap =new HashMap(); ("Authorization", token); ("Content-type", "application/json"); // 判断token获取的user信息 String tkJson = tPost(ssoGetUserURL, headMap, param); JSONObject resultJson = ject(tkJson); String employeeNo=ing("EmployeeNo");