当前位置: 首页 > news >正文

成立网站是不是需要先成立公司iis wordpress 兼容

成立网站是不是需要先成立公司,iis wordpress 兼容,创业计划书建设网站,临沂建设规划局网站项目中经常会用到向第三方系统发送请求来传递数据或者获得信息#xff0c;一般用的比较多的为HttpClient 和 HttpRequest#xff0c;这里简要总结一下 HttpClient 和 HttpRequest 的用法 一、HttpClient 1. 发送get请求 public static String get(String url, MapStri…项目中经常会用到向第三方系统发送请求来传递数据或者获得信息一般用的比较多的为HttpClient 和 HttpRequest这里简要总结一下 HttpClient 和 HttpRequest 的用法 一、HttpClient 1. 发送get请求 public static String get(String url, MapString, String headMap, int timeout) {String result null;CloseableHttpClient httpclient HttpClients.createDefault();CloseableHttpResponse response null;try {HttpGet httpGet new HttpGet(url);RequestConfig requestConfig RequestConfig.custom().setConnectTimeout(timeout).build();httpGet.setConfig(requestConfig);setHead(httpGet, headMap);response httpclient.execute(httpGet);HttpEntity entity response.getEntity();result EntityUtils.toString(entity, UTF-8);EntityUtils.consume(entity);} catch (Exception e) {LOG.error(HttpGet [{}] error: {}, url, e.getMessage(), e);throw new RuntimeException(e.getMessage(), e);} finally {try {if (null ! response) {response.close(); }httpclient.close();} catch (IOException e) {LOG.error(HttpGet [{}] httpclient close error: {}, url, e.getMessage(), e);}}return result; } 1. 发送post请求 public static String postJson(String url, String body, MapString, String headMap, int timeout) {CloseableHttpClient httpClient HttpClients.createDefault();CloseableHttpResponse response null;try {HttpPost httpPost new HttpPost(url);httpPost.addHeader(Content-Type, application/json;charsetutf-8);setHead(httpPost, headMap);RequestConfig requestConfig RequestConfig.custom().setConnectTimeout(timeout).build();httpPost.setConfig(requestConfig);httpPost.setEntity(new StringEntity(body, UTF-8));response httpClient.execute(httpPost);HttpEntity entity response.getEntity();String responseContent EntityUtils.toString(entity, UTF-8);EntityUtils.consume(entity);return responseContent;} catch (Exception e) {LOG.error(HttpPostJson [{}] error: {}, url, e.getMessage(), e);throw new RuntimeException(e.getMessage(), e);} finally {try {response.close();httpClient.close();} catch (IOException e) {LOG.error(HttpPostJson [{}] httpclient close error: {}, url, e.getMessage(), e);}} } private static void setHead(HttpRequestBase httpRequestBase, MapString, String headMap) {if (headMap ! null headMap.size() 0) {SetString keySet headMap.keySet();for (String key : keySet) {httpRequestBase.addHeader(key, headMap.get(key));}} } 优点连接池复用HTTP连接、重试、代理机制社区活跃性能更加优异 缺点配置和API使用较为复杂 二、HttpRequest 1. 发送get请求 public static String get(String methodName, String url, MapString, Object paramMap, MapString, String headers){return HttpRequest.get(url).addHeaders(headers).form(paramMap).execute().body(); } 2. 发送post请求 public static String postForm(String methodName, String url, MapString, Object paramMap, MapString, String headers, String paramStr){return HttpRequest.post(url).addHeaders(headers).form(paramMap).body(paramStr).execute().body(); } 优点功能简单整体比较易用 缺点性能一般社区支持较弱 三、对比 hutool 的 HttpRequest 底层是基于 HttpClient 的是对其进行了封装提供了更加简便的API请求使用 HttpRequest 可在一行代码中实现发送简单的HTTP请求如果需要使用 HttpClient 更加复杂的操作则可以通过自定义 HttpClient 并通过 setHttpClient() 方法传入 HttpClient 例如通过自定义Httpclient实现设置最大连接数量 // 创建连接池管理器 PoolingHttpClientConnectionManager connectionManager new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(100); // 设置最大连接数 connectionManager.setDefaultMaxPerRoute(20); // 设置每个路由的最大连接数// 创建自定义的HttpClient HttpClientBuilder httpClientBuilder HttpClientBuilder.create().setConnectionManager(connectionManager);// 使用 Hutool 的 HttpRequest 发送请求 HttpResponse response HttpRequest.get(https://example.com).timeout(5000) // 设置超时时间.setHttpClient(httpClientBuilder.build()) // 设置自定义的HttpClient.execute(); 总结 小型简单项目可使用 HttpRequest 快速请求较大型复杂项目适合使用 HttpClientHttpClient 引入 httpclient 依赖HttpRequest 引入 hutool 依赖如果有连接池、重试、代理等机制的需求则可使用 HttpClient高性能高并发有复杂Http操作的场景则可使用 HttpClient
http://www.w-s-a.com/news/519855/

相关文章:

  • 可以做翻译任务的网站陕西省建设厅八大员证
  • 昆明 网站推广重庆网页优化seo公司
  • 网站排名下降怎么上去设计一套app页面多少钱
  • 专门用来查找网址的网站查公司名字是否被注册
  • 自己创建网站教程河南省建设厅官方网站李学军
  • 一个网站需要多少容量怎样免费设计网站建设
  • 建设工程交易中心网站12306的网站是哪个公司做的
  • 建设网站经营范围自己给公司做网站
  • 河北省住房建设厅政务网站网络营销推广的岗位职责有哪些
  • 上海网站建设优化价格孝义做网站的公司
  • 哪个公司网站做的最好义乌 网站 制作
  • 百度站长工具综合查询wordpress 上传pdf
  • 旅游短租公寓网站建设深圳龙岗招聘网
  • 做海淘是在哪个网站网络查控系统设计方案
  • o2o网站建设代理商微信公众号开发文档
  • 网站设计课程总结关于网站备案的公告
  • 网站建设与运营意义到哪查找网站域名
  • 网站及单位网站建设情况眉县住房和城市建设局网站
  • 网站是否能够被恶意镜像wordpress占用
  • 经典设计网站网站等保测评怎么做
  • 重庆做网站公司贴吧廊坊公司快速建站
  • 海外贸易在什么网站做怎么排名到百度第一页
  • 线上注册公司是在哪个网站做高仿网站
  • 网站构架图网上推广平台哪个好
  • 公司网站首页图片素材vi设计的目的和意义
  • 网站的需求分析都有哪些内容济南营销型网站建设团队
  • 怎么选择优秀的网站建设公司生鲜网站开发
  • 如何编写网站建设销售的心得网站的权限管理怎么做
  • 网站业务员好做吗无忧网站优化
  • 网站随机代码网站建设费 账务处理