public class InsuranceUtil {
public static JSONObject getHttpResponseJson(String url,Map<String,Object> param,String XAPPID,String XAPPKEY){
CloseableHttpClient httpclient = null;
CloseableHttpResponse response = null;
JSONObject jsonObject = null;
String jsonString = com.alibaba.fastjson.JSONObject.toJSONString(param);
try {
//请求发起客户端
httpclient = HttpClients.createDefault();
//参数集合
// if (null == param) {
// param = new HashMap<String, Object>();
// }
// List<NameValuePair> pairList = new ArrayList<NameValuePair>(param.size());
// for (Map.Entry<String, Object> entry : param.entrySet()) {
// NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry.getValue().toString());
// pairList.add(pair);
// }
// 表单方式提交
// HttpEntity paramEntity = new UrlEncodedFormEntity(pairList,"UTF-8");
// post.setEntity(paramEntity);
//通过post方式访问
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/json;charset=UTF-8");
// post.addHeader("X-APP-ID",XAPPID);
// post.addHeader("X-APP-KEY",XAPPKEY);
StringEntity stringEntity = new StringEntity(jsonString, "UTF-8");
stringEntity.setContentType("TEXT/JSON");
post.setEntity(stringEntity);
response = httpclient.execute(post);
HttpEntity valueEntity = response.getEntity();
String content = EntityUtils.toString(valueEntity);
jsonObject = JSONObject.parseObject(content);
return jsonObject;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(httpclient != null){
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(response != null){
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return jsonObject;
}
}
调用第三方接口
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 原文链接:https://blog.csdn.net/qq_35860138/article/details/82...
- 前提:前后端分离项目 1、本地开发 package.json中设置proxy利用node跨域 2、线上打包——炒鸡...
- 1.坐标依赖 2.分析 在日常开发中,我们可能会去对接一些第三方的接口,亦或者是在一个项目中对接另外一个项目.这样...
- 一、中通快递。对接 获取快件轨迹信息 接口 中通开放平台地址:https://zop.zto.com/apiDoc...