jdk7下httpclient请求https问题

今天和商户技术解决httpclient请求https问题,对方一直提示“javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated”,无论我怎么调试都不行,最后悲催的发现对方使用的jdk7(我本地使用的是jdk6),原来JDK7 has changed the default Java security settings to disable MD2 algorithm to sign SSL certificates.,解决方案为:

The default Java security settings can be re-enabled by editing JDK_HOME/jre/lib/security/java.security and commenting out the following line:

jdk.certpath.disabledAlgorithms=MD2

to

#jdk.certpath.disabledAlgorithms=MD2
Windows path to the config file: C:\Program Files (x86)\Java\jre7\lib\security


附:httputil中请求https需要加入以下代码

public static org.apache.http.client.HttpClient wrapClient(
			org.apache.http.client.HttpClient base) {
		try {
			SSLContext ctx = SSLContext.getInstance("TLS");
		
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用jdk11的httpclient实现发送http请求的步骤如下: 1.创建HttpClient对象,可以通过HttpClient.newBuilder()方法来创建,也可以直接使用HttpClient.newHttpClient()方法来创建。 2.创建HttpRequest对象,可以通过HttpRequest.newBuilder()方法来创建,也可以直接使用HttpRequest.create()方法来创建。 3.发送请求,可以通过HttpClient.send()方法来发送请求,该方法会返回一个HttpResponse对象,通过该对象可以获取响应的状态码、响应头、响应体等信息。 下面是一个简单的示例代码: ``` import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.time.Duration; public class HttpClientDemo { public static void main(String[] args) throws Exception { // 创建HttpClient对象 HttpClient client = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_1_1) .connectTimeout(Duration.ofSeconds(2)) .build(); // 创建HttpRequest对象 HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://www.example.com")) .GET() .build(); // 发送请求 HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); // 获取响应信息 int statusCode = response.statusCode(); String responseBody = response.body(); HttpHeaders headers = response.headers(); // 输出响应信息 System.out.println("Status Code: " + statusCode); System.out.println("Response Body: " + responseBody); System.out.println("Headers: " + headers); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值