首页 文章 精选 留言 我的

精选列表

搜索[服务],共10000篇文章
优秀的个人博客,低调大师

【飞天存储服务月报】2018年6月刊

【重点新闻】 1、产品降价:阿里云对象存储OSS刷新行业最低价 6月7日,在2018云栖大会·上海峰会上,阿里云宣布云存储产品开启新一轮降价,其中对象存储OSS产品价格下调了18.9%,刷新了云存储的全网最低价,表格存储TableStore按量读写及资源包最高下调50%。调价后,对象存储OSS标准型的最低售价为0.12元/GB/月,购买500TB存储资源包相当于用户每月最多可节省7000多元。此番调价将进一步扩大云存储对线下存储的竞争优势。 2、耗时仅45天!全球互联网史上规模最大的公共云数据迁移完成 在2018云栖大会上海峰会上,阿里云和115科技共同宣布完成全球互联网史上规模最大的公共云数据迁移,总量超过100PB。同时,整个过程仅耗时45天,刷新了百PB级数据公共云迁移的新纪录,打破AWS用时3个月完成70PB数据迁移记录,成为全球

优秀的个人博客,低调大师

Java工具类之在服务器发送HTTP请求

版权声明:本文为博主原创文章,未经博主允许不得转载。博客源地址为zhixiang.org.cn https://blog.csdn.net/myFirstCN/article/details/80880234 使用之前首先添加maven依赖或者是jar包 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> 下面给出工具类代码,一个简单发送Get和Post请求的例子 public class HttpUtils { /* *发送简单post请求 */ public static JSONObject post(String url) { HttpPost post = new HttpPost(url); return getResult(post); } /* *发送带Header的post请求 */ public static JSONObject post(String url, Map<String, String> map) { HttpPost post = new HttpPost(url); if (!map.isEmpty()) { Set<Map.Entry<String, String>> entrys = map.entrySet(); for (Map.Entry<String, String> entry : entrys) { post.setHeader(entry.getKey(), entry.getValue()); } } return getResult(post); } /* *发送带Header的get请求 */ public static JSONObject get(String url, Map<String, String> map) { HttpGet get = new HttpGet(url); if (!map.isEmpty()) { Set<Map.Entry<String, String>> entrys = map.entrySet(); for (Map.Entry<String, String> entry : entrys) { get.setHeader(entry.getKey(), entry.getValue()); } } return getResult(get); } /* *发送简单的get请求 */ public static JSONObject get(String url) { HttpGet get = new HttpGet(url); return getResult(get); } /* *发送请求方法,请求响应为JSONObject */ private static JSONObject getResult(HttpRequestBase requestBase) { CloseableHttpClient httpClient = HttpClients.createDefault(); String result = null; try { result = EntityUtils.toString(httpClient.execute(requestBase).getEntity()); httpClient.close(); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { return new JSONObject(JSON.parseObject(result)); } } /* *当请求响应为String时 */ public static String getString(String url) { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet get = new HttpGet(url); String result = null; try { result = EntityUtils.toString(httpClient.execute(get).getEntity()); httpClient.close(); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { return result; } } } 使用之前首先添加maven依赖或者是jar包 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> 下面给出工具类代码,一个简单发送Get和Post请求的例子 public class HttpUtils { /* *发送简单post请求 */ public static JSONObject post(String url) { HttpPost post = new HttpPost(url); return getResult(post); } /* *发送带Header的post请求 */ public static JSONObject post(String url, Map<String, String> map) { HttpPost post = new HttpPost(url); if (!map.isEmpty()) { Set<Map.Entry<String, String>> entrys = map.entrySet(); for (Map.Entry<String, String> entry : entrys) { post.setHeader(entry.getKey(), entry.getValue()); } } return getResult(post); } /* *发送带Header的get请求 */ public static JSONObject get(String url, Map<String, String> map) { HttpGet get = new HttpGet(url); if (!map.isEmpty()) { Set<Map.Entry<String, String>> entrys = map.entrySet(); for (Map.Entry<String, String> entry : entrys) { get.setHeader(entry.getKey(), entry.getValue()); } } return getResult(get); } /* *发送简单的get请求 */ public static JSONObject get(String url) { HttpGet get = new HttpGet(url); return getResult(get); } /* *发送请求方法,请求响应为JSONObject */ private static JSONObject getResult(HttpRequestBase requestBase) { CloseableHttpClient httpClient = HttpClients.createDefault(); String result = null; try { result = EntityUtils.toString(httpClient.execute(requestBase).getEntity()); httpClient.close(); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { return new JSONObject(JSON.parseObject(result)); } } /* *当请求响应为String时 */ public static String getString(String url) { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet get = new HttpGet(url); String result = null; try { result = EntityUtils.toString(httpClient.execute(get).getEntity()); httpClient.close(); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { return result; } } }

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册