Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在尝试在RESTfulWebService中发送HTTPS请求,并获取javax.net.ssl.SSLHandshakeException_Java_Ssl - Fatal编程技术网

我正在尝试在RESTfulWebService中发送HTTPS请求,并获取javax.net.ssl.SSLHandshakeException

我正在尝试在RESTfulWebService中发送HTTPS请求,并获取javax.net.ssl.SSLHandshakeException,java,ssl,Java,Ssl,下面的代码可以很好地用于HTTP请求,但不能用于HTTPS。我得到这个错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.validator异常:PKIX路径生成失败: sun.security.provider.certpath.SunCertPathBuilderException:无法 找到请求目标的有效证书路径 当我通过hurl.it发送请求时,带有HTTPS的URL工作正常。是否有用于https请求的客户端生成

下面的代码可以很好地用于HTTP请求,但不能用于HTTPS。我得到这个错误:

javax.net.ssl.SSLHandshakeException: sun.security.validator.validator异常:PKIX路径生成失败: sun.security.provider.certpath.SunCertPathBuilderException:无法 找到请求目标的有效证书路径

当我通过
hurl.it
发送请求时,带有HTTPS的URL工作正常。是否有用于https请求的客户端生成器

这是我的密码:

HttpClient httpClient = null;
        HttpRequestBase baseRequest = null;
        String apiResponse = null;
        try {
            httpClient = getClientConnection(url, clientConfiguration.isProxyEnabled());
            baseRequest = getHttpClient(url, clientConfiguration.getRequestMethod());

            if (headers != null) {
                for (Entry<String, String> entry : headers.entrySet()) {
                    baseRequest.addHeader(entry.getKey(), entry.getValue());
                }
            }
            if (!clientConfiguration.getRequestMethod().equals(RequestMethod.GET)) {
                // checking for post body parameters
                if (clientConfiguration.getURLParameters() != null
                        && !clientConfiguration.getURLParameters().isEmpty()) {
                    List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                    for (Entry<String, String> param : clientConfiguration.getURLParameters().entrySet()) {
                        postParameters.add(new BasicNameValuePair(param.getKey(), param.getValue()));
                    }
                    if (baseRequest instanceof HttpPost) {
                        ((HttpPost) baseRequest).setEntity(new UrlEncodedFormEntity(postParameters));
                    } else if (baseRequest instanceof HttpPut) {
                        ((HttpPut) baseRequest).setEntity(new UrlEncodedFormEntity(postParameters));
                    } else if (baseRequest instanceof CoreDelete) {
                        ((CoreDelete) baseRequest).setEntity(new UrlEncodedFormEntity(postParameters));
                    }
                }
            }
            System.out.println("URL " + url);
            if (clientConfiguration.getRequestBody() != null) {
                HttpEntity entity = new ByteArrayEntity(clientConfiguration.getRequestBody().getBytes("UTF-8"));
                if (baseRequest instanceof HttpPost) {
                    ((HttpPost) baseRequest).setEntity(entity);
                } else if (baseRequest instanceof HttpPut) {
                    ((HttpPut) baseRequest).setEntity(entity);
                } else if (baseRequest instanceof CoreDelete) {
                    ((CoreDelete) baseRequest).setEntity(entity);
                }
            }
            HttpResponse response = httpClient.execute(baseRequest);
HttpClient-HttpClient=null;
HttpRequestBase baseRequest=null;
字符串apiResponse=null;
试一试{
httpClient=getClientConnection(url,clientConfiguration.isProxyEnabled());
baseRequest=getHttpClient(url,clientConfiguration.getRequestMethod());
如果(标题!=null){
for(条目:headers.entrySet()){
baseRequest.addHeader(entry.getKey(),entry.getValue());
}
}
如果(!clientConfiguration.getRequestMethod().equals(RequestMethod.GET)){
//检查柱体参数
if(clientConfiguration.getURLParameters()!=null
&&!clientConfiguration.getURLParameters().isEmpty()){
List postParameters=new ArrayList();
对于(条目参数:clientConfiguration.getURLParameters().entrySet()){
添加(新的BasicNameValuePair(param.getKey(),param.getValue());
}
if(HttpPost的baseRequest实例){
((HttpPost)baseRequest).setEntity(新的UrlEncodedFormEntity(后参数));
}else if(HttpPut的baseRequest实例){
((HttpPut)baseRequest).setEntity(新的UrlEncodedFormEntity(后参数));
}else if(CoreDelete的baseRequest实例){
((CoreDelete)baseRequest).setEntity(新的UrlEncodedFormEntity(后参数));
}
}
}
System.out.println(“URL”+URL);
if(clientConfiguration.getRequestBody()!=null){
HttpEntity=newbyteArrayEntity(clientConfiguration.getRequestBody().getBytes(“UTF-8”);
if(HttpPost的baseRequest实例){
((HttpPost)baseRequest).setEntity(entity);
}else if(HttpPut的baseRequest实例){
((HttpPut)baseRequest).setEntity(entity);
}else if(CoreDelete的baseRequest实例){
((CoreDelete)baseRequest).setEntity(entity);
}
}
HttpResponse response=httpClient.execute(baseRequest);

这可能有帮助:您的服务端点是否具有有效的HTTPS证书,并且配置是否正确?我是否需要在本地系统上配置HTTPS证书?如何配置?这可能有帮助:您的服务端点是否具有有效的HTTPS证书,并且配置是否正确?我是否需要在本地系统上配置HTTPS证书嗯,怎么了?