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的封装方法
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 1.使用记事本(或其他文本编辑器)创建一个protocal.reg文件,并写入以下内容 Windows Regis...
- 业务场景今天工作中 遇到的业务场景:委托审批流中 需要调BPM审核流完成委托,并保存委托关系(A委托了什么项目给B...
- RMI(即Remote Method Invoke远程方法调用)。在Java中,只要一个类extends了java...