private static String post(String postUrl, String jsonParam,String token) throws Exception {
System.out.println("------方法:post------提示:远程调用(开始),postUrl:"+postUrl);
String json = "";
try {
RequestConfig config = RequestConfig.custom().setSocketTimeout(200000).setConnectTimeout(50000).setConnectionRequestTimeout(50000).build();
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(postUrl);
post.setHeader("Content-type", "application/json; charset=utf-8");
post.setHeader("Connection", "Close");
post.setHeader("token",token);
StringEntity entity = new StringEntity(jsonParam, Charset.forName("UTF-8"));
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
post.setEntity(entity);
post.setConfig(config);
HttpResponse response = client.execute(post);
System.out.println(response);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity resEntity = response.getEntity();
json = EntityUtils.toString(resEntity, "utf-8");
}
} catch (UnsupportedEncodingException e) {
System.out.println(e.getStackTrace());
throw new RuntimeException("post请求异常发生");
} catch (ClientProtocolException e) {
System.out.println(e.getStackTrace());
throw new RuntimeException("post请求异常发生");
} catch (ParseException e) {
System.out.println(e.getStackTrace());
throw new RuntimeException("post请求异常发生");
} catch (IOException e) {
System.out.println(e.getStackTrace());
throw new RuntimeException("post请求异常发生");
}
System.out.println("------方法:post------提示:远程调用(结束),result:" + json);
return json;
}
远程调用URL的封装方法
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.使用记事本(或其他文本编辑器)创建一个protocal.reg文件,并写入以下内容 Windows Regis...
- 业务场景今天工作中 遇到的业务场景:委托审批流中 需要调BPM审核流完成委托,并保存委托关系(A委托了什么项目给B...
- RMI(即Remote Method Invoke远程方法调用)。在Java中,只要一个类extends了java...