/*
* 文 件 名: GetCSATHttpsTest.java
* 版 权: Copyright 2000-2009 Huawei Tech. Co. Ltd. All Rights Reserved.
* 描 述: <描述>
* 修 改 人: cwx223372
* 修改时间: 2015年9月11日
* 修改版本:
*/
package com.huawei.csservice.action.service;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.junit.Test;
import com.huawei.common.components.encrypt.EncryptedUtils;
import com.huawei.common.components.encrypt.HmacSHA256Encrypter;
import com.huawei.common.system.COMException;
import com.huawei.common.utils.CharsetUtils;
import com.huawei.common.utils.access.jackson.JacksonMapper;
import com.huawei.csservice.action.service.event.GetCSATREvt;
public class GetCSATHttpsTest
{
public static String httpsurl = "https:www.baidu.com";
/**
* 测试
*/
@Test
public void testHttps()
throws IOException, NoSuchAlgorithmException, KeyManagementException, COMException
{
TrustManager myX509TrustManager = new X509TrustManager()
{
@Override
public X509Certificate[] getAcceptedIssuers()
{
return new X509Certificate[] {};
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{
}
};
//设置SSLContext
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] {myX509TrustManager}, null);
// 创建URL对象
URL myURL = new URL(httpsurl);
// 创建HttpsURLConnection对象,并设置其SSLSocketFactory对象
HttpsURLConnection httpsConn = (HttpsURLConnection)myURL.openConnection();
//设置套接工厂
httpsConn.setSSLSocketFactory(sslcontext.getSocketFactory());
HostnameVerifier hostNameVerify = new HostnameVerifier()
{
/**
* Always return true
*/
public boolean verify(String urlHostName, SSLSession session)
{
return true;
}
};
httpsConn.setHostnameVerifier(hostNameVerify);
//加入post数据
String postdata = getPostData();
httpsConn.setRequestMethod("POST");
httpsConn.setDoOutput(true);
DataOutputStream out = new DataOutputStream(httpsConn.getOutputStream());
if (null != postdata)
{
out.writeBytes(postdata);
}
out.flush();
out.close();
//获取输入流
BufferedReader in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream()));
int code = httpsConn.getResponseCode();
if (HttpsURLConnection.HTTP_OK == code)
{
String temp = in.readLine();
//輸出字符串
while (temp != null)
{
System.out.println(temp);
temp = in.readLine();
}
}
}
/**
* 获取post数据
*/
private static String getPostData()
throws UnsupportedEncodingException, COMException
{
return "";
}
}
相关推荐
java支持https的Post请求,采用SSLContext绕过https的安全证书校验,含实例main函数
(完整版)JAVA利用HttpClient进行POST请求(HTTPS).doc
NULL 博文链接:https://fanshuyao.iteye.com/blog/2436277
java发送http/https请求(get/post)代码,java 通过发送json,post请求,返回json数据的方法 java 通过发送json,post请求,返回json数据的方法
java的get和post请求,获取json的工具类,https时会存在ssl校验的问题,工具会自动去除ssl校验。
自己项目里的,可用
java发送https请求,解决了数组证书的问题,所依赖的jar都有
Java发 Https请求工具类 支持SSL。 自定义请求方式 GET POST... 微信自用, 发Https请求工具类,支持SSL SSL Https
java_https_post(兼容http).zip
okhttp3进行https的post调用。代码比较详细,也有错误说明。
java模拟HTTP发送post和get请求工具类,使用httpClient类
下面小编就为大家带来一篇JAVA利用HttpClient进行POST请求(HTTPS)实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起 小编过来看看吧
java实现get请求post请求,文件传输 /** * 发送https请求 * @param requestUrl 请求地址 * @param requestMethod 请求方式(GET、POST) * @param outputStr 提交的数据 * @return 返回微信服务器响应的信息 ...
javaHTTPS的post与GET提交取得数据,里面包含了jar包和完整的例子,可以直接使用。httpclient-4.5。
java实现读取证书访问https接口并获取返回数据.证书格式cer,der,crt等。
压缩包里包含http和https两种请求,第一个文件是http请求包含post和get两种方式,剩下的是https的请求,最后一个文件里包含https的post和get两种方式。中间的两个是post 和 get 分开写的,按照需要引用吧
此工具用于Post接口测试,并且支持HTTPS, 可以储存经常使用的测试链接,可用于PHP,JAVA程序员和测试员
Java发送http请求、https请求,post和get都支持
后端springboot + java + mysql + idea 前后端分离开发 http://localhost:8080/login.html 数字型 http://xxx.xxxx.com/?page=2 字符漏洞 https://xxxx.com&topicid=4 xss漏洞格式 https://xxxx.com&topicid= ...