Java使用Http远程调用
↓↓
↓↓
↓↓
正文
public Object backstagePushMessageT(@RequestParam(value = "pushObjecType") String pushObjecType,
@RequestParam(value = "toUserIds", required = false) String toUserIds,
@RequestParam(value = "groupId", required = false) String groupId,
@RequestParam(value = "pushMessage") String pushMessage,
HttpServletRequest request) {
HttpClient client = HttpClients.createDefault();
String url = null;
String appKey = "appKey";
//签名
String Signature = "1d938e487c41f523dfscb3sd263be896";
//参数
List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
JSONObject jsonObject = new JSONObject();
url = URL + "/api/im/httpMessage/windowNtf";
nvps.add(new BasicNameValuePair("groupId", groupId));
nvps.add(new BasicNameValuePair("msg", pushMessage));
HttpPost post = HttpPostUtil.getHttpPost(url, appKey, Signature);
try {
post.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
HttpResponse res = client.execute(post);
if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String result = EntityUtils.toString(res.getEntity());// 返回json格式:
System.out.println("result;" + result);
jsonObject = JSONObject.parseObject(result);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return jsonObject;
}
来源:https://blog.csdn.net/weixin_43618214/article/details/100972363