资源简介
基于不同客户需求,发送https post请求,参数格式可为json,text,xml
代码片段和文件信息
package com.gmt.server.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
public class HttpsProxy {
private static final String METHOD_POST = “POST“;
private static final String DEFAULT_CHARSET = “utf-8“;
public static String doPost(String url String params
String charset int connectTimeout int readTimeout) throws Exception {
String ctype = “application/json;charset=“ + charset;
byte[] content = {};
if(params != null){
System.out.println(“上传参数:“+params);
content = params.getBytes(charset);
}
return doPost(url ctype content connectTimeout readTimeout);
}
public static String doPost(String url String ctype byte[] content
int connectTimeoutint readTimeout) throws Exception {
HttpsURLConnection conn = null;
OutputStream out = null;
String rsp = null;
try {
try{
SSLContext ctx = SSLContext.getInstance(“TLS“);
ctx.init(new KeyManager[0] new TrustManager[] {new DefaultTrustManager()}
new SecureRandom());
SSLContext.setDefault(ctx);
conn = getConnection(new URL(url) METHOD_POST ctype);
conn.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname SSLSession session) {
return true;
}
});
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);
}catch(Exception e){
throw e;
}
try{
out = conn.getOutputStream();
out.write(content);
rsp = getResponseAsString(conn);
}catch(IOException e){
throw e;
}
}finally {
if (out != null) {
out.close();
}
if (conn != null) {
conn.disconnect();
}
}
return rsp;
}
private static class DefaultTrustManager implements javax.net.ssl.X509TrustManager {
public void checkClientTrusted(X509Certificate[] arg0 String arg1) throws CertificateException {}
public void checkServerTrusted(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5861 2017-10-17 10:14 HttpsProxy.java
文件 4060 2017-12-01 15:33 MySSLProtocolSocketFactory.java
文件 3084 2017-12-01 16:44 HttpUtils.java
- 上一篇:FRM二级公式表
- 下一篇:stm32串口调试助手
相关资源
- httpclient请求httpsdemo
- 易语言HTTPS代理服务器源码
- 从https://studiostyl.es的son-of-obsidian.vss
- httpsqs-1.7.tar.gz
- 微软https kb968730
- pb9 通过http、https协议post
- https://download.csdn.net/download/p_xiaojia/9
- https密钥和证书
- [delphi]简单HTTP服务器架设源码
- Delphi Https-Post
- libeay32.dll 、 ssleay32.dll动态链接库
- httpserv.rar
- Delphi7_OpenSSL.rar
- 调用https协议的webservice,以及证书手
- Fiddler4 以及证书https
- Delphi下WinPCap开发基础 一个简单的Ht
- 易语言源码易语言HTTPS代理服务器源码
- Nginx 同IP 多域名 HTTPS SSL 配置
- Ingress nginx部署及实战 http https代理
- pbfunc外部函数扩展(1.2.2.17) 2016-09
- webSocket配置wss访问
- wsdl2h.exe代https功能
- 易语言HTTPS文件(带进度)
- http2文档报文及分析
- 支持HTTPS的Get和Post函数
- 支持HTTPS的libcurl
- delphi_xe7_idhttp10——win7_64位下访问ht
- 彻底解决IE无法浏览密钥长度512位以下
评论
共有 条评论