HTTP工具

简介: HTTP工具

HTTP-GET带header请求
HTTP-POST带header请求
HTTPS-POST带header请求
Java
运行代码
复制代码
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//设置链接超时和请求超时等参数,否则会长期停止或者崩溃

public static String sendHttpsPost(String url, JSONObject params) {
String responseContent = null;
CloseableHttpClient httpClient = null;
CloseableHttpResponse httpResponse = null;
try {
HttpPost httpPost = new HttpPost(url);
// header
httpPost.addHeader("AppKey", SystemConstants.APP_KEY);
httpPost.addHeader("Secret", SystemConstants.SECRET);
// body
httpPost.setEntity(new StringEntity(params.toString(), "UTF-8"));
httpClient = HttpClients.custom().setSSLSocketFactory(createSslConnSocketFactory()).setDefaultRequestConfig(requestConfig).build();
httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
responseContent = EntityUtils.toString(httpEntity, "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(null != httpResponse) {
httpResponse.close();
}
if (null != httpClient) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return responseContent;
}

/**

 * 创建SSL安全连接
 * @return SSLConnectionSocketFactory
 */

private static SSLConnectionSocketFactory createSslConnSocketFactory() {
SSLConnectionSocketFactory sslsf = null;
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true).build();
sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() {

        @Override
        public boolean verify(String arg0, SSLSession arg1) {
            return true;
        }

        @Override
        public void verify(String host, SSLSocket ssl) {
        }

        @Override
        public void verify(String host, X509Certificate cert) {
        }

        @Override
        public void verify(String host, String[] cns, String[] subjectAlts) {
        }
    });
} catch (GeneralSecurityException e) {
    e.printStackTrace();
}
return sslsf;

}

相关文章
|
11月前
|
编解码 测试技术 索引
性能工具之 Jmeter 使用 HTTP 请求编写 HLS 脚本
在我们简要介绍了 HLS 协议的基础知识,接下来我们详细介绍一种使用 Jmeter 编写压测 HLS 协议脚本的方法。
185 1
性能工具之 Jmeter 使用 HTTP 请求编写 HLS 脚本
|
11月前
|
网络协议 Linux 网络安全
curl(http命令行工具):Linux下最强大的网络数据传输工具
curl(http命令行工具):Linux下最强大的网络数据传输工具
301 0
|
Java
百度搜索:蓝易云【hutool Http 工具发送POST请求的几种方式。】
以上是使用Hutool发送POST请求的几种方式。根据实际需求和代码复杂度,选择合适的方式来发送POST请求。
393 0
|
10月前
|
中间件
流量回放工具之GoReplay output-http 源码分析
【6月更文挑战5天】流量回放工具之GoReplay output-http 源码分析
136 2
|
10月前
流量回放工具之 GoReplay output-http-stats(HTTP请求统计) 源码分析
【6月更文挑战4天】流量回放工具之 GoReplay output-http-stats(HTTP请求统计) 源码分析
119 4
|
9月前
|
SQL
常用工具类---SQL工具,HTTP工具
SQL工具,HTTP工具,两个实用小工具~~~
|
10月前
|
数据采集 Java API
Java HTTP客户端工具的演变之路
Java HTTP客户端工具的演变之路
|
11月前
|
JSON API 定位技术
.NET集成DeveloperSharp实现http网络请求&与其它工具的比较
该内容介绍了一个支持.NET Core 2.0及以上和.NET Framework 4.0及以上的HTTP请求调用方法,主要讨论了POST和GET两种形式。POST请求较为常见,涉及调用地址、发送参数、HTTP请求头和编码格式设置。文中提供了一个使用DeveloperSharp库发送POST请求的C#代码示例,用于发送短信,其中`IU.HttpPost`方法用于执行POST请求。此外,还提到了`HttpPost`方法的参数和返回值说明。最后简要提及了GET请求,通常用于URL带有查询参数的情况,并给出一个简单的GET请求示例。
|
11月前
|
JSON JavaScript 网络安全
新款HTTP代理工具Proxyman(界面美观、功能强大)
新款HTTP代理工具Proxyman(界面美观、功能强大)
2503 0