Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/128.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
Java Apache httpPost在url中将https更改为http_Java - Fatal编程技术网

Java Apache httpPost在url中将https更改为http

Java Apache httpPost在url中将https更改为http,java,Java,我想用apache httpclient调用https post方法。 我在互联网上找不到解决办法。 问题是当我调用https方法时,我不知道为什么会改为http 我尝试了很多方法,但都在url中将https更改为http RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(20000) .setSocketTimeout(20000) .build();

我想用apache httpclient调用https post方法。 我在互联网上找不到解决办法。 问题是当我调用https方法时,我不知道为什么会改为http

我尝试了很多方法,但都在url中将https更改为http

RequestConfig requestConfig = RequestConfig.custom()
        .setConnectTimeout(20000)
        .setSocketTimeout(20000)
        .build();

StringEntity entity = new StringEntity("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
    "  <soap:Body>\n" +
    "    <GetComplaintData xmlns=\"http://tempuri.org/\">\n" +
    "      <UserName></UserName>\n" +
    "      <Password></Password>\n" +
    "      <TrackingCode>"+complaintCode+"</TrackingCode>\n" +
    "    </GetComplaintData>\n" +
    "  </soap:Body>\n" +
    "</soap:Envelope>", "UTF-8");


HttpUriRequest request = RequestBuilder.create('POST')
        .setConfig(requestConfig)
        .setUri("https://195.cra.ir:8085/Complaint.asmx?op=GetComplaintData")
        .setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8")
        .setEntity(entity)
        .build();

HttpClientBuilder.create().build().withCloseable {httpClient ->

    httpClient.execute(request).withCloseable {response ->

        String res = "RESPONSE:" + "\n" + response.getStatusLine() + "\n" + "Headers: " +
                response.getAllHeaders() + "\n" +
                (response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "") + "\n";

         println(res.toString()+"_________________________-")
    }
}
RequestConfig RequestConfig=RequestConfig.custom()
.setConnectTimeout(20000)
.setSocketTimeout(20000)
.build();
StringEntity实体=新的StringEntity(“\n”+
“\n”+
“\n”+
“\n”+
“\n”+
“”+投诉代码+“\n”+
“\n”+
“\n”+
“UTF-8”;
HttpUriRequest request=RequestBuilder.create('POST'))
.setConfig(requestConfig)
.setUri(“https://195.cra.ir:8085/Complaint.asmx?op=GetComplaintData")
.setHeader(HttpHeaders.CONTENT_类型,“text/xml;charset=UTF-8”)
.setEntity(实体)
.build();
HttpClientBuilder.create().build().withCloseable{httpClient->
httpClient.execute(请求).withCloseable{response->
String res=“RESPONSE:”+“\n”+RESPONSE.getStatusLine()+“\n”+”标题:+
response.getAllHeaders()+“\n”+
(response.getEntity()!=null?EntityUtils.toString(response.getEntity()):“”)+“\n”;
println(res.toString()+“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
}
}
我希望url不会将https更改为http。
抱歉,我解释得不好。谢谢

您只需搜索:
ApacheHTTP客户端帖子
,就可以在Web上找到大量示例。在任何情况下,这都适用于您,具体取决于您使用的版本:

final String envelope = "<soap:Envelope ... </soap:Envelope>";
final StringEntity entity = new StringEntity(envelope, StandardCharsets.UTF_8);
entity.setChunked(true);
final HttpPost httpPost = new HttpPost("https://your.url?soap=Operation");
httpPost.setEntity(entity);
httpPost.addHeader("SOAPAction", "YourSOAPActionHere");
final CloseableHttpResponse response = HttpClients.createDefault().execute(httpPost);
response.getStatusLine();
EntityUtils.toString(response.getEntity());

最终字符串信封=“你为什么认为它正在改变?在内部,它使用
java.net.URI
,因此如果可以解析它,它必须保持原样。检查
请求时,
uri
的值是多少?您好。您是对的,uri没有更改。您可以添加https的httpPost示例吗??谢谢。我使用了代码,但错误仍然存在。{“errorCode”:400,“errors”:“连接到195.cra.ir:8085[195.cra.ir/185.155.236.64]失败:连接超时(连接超时)\n连接超时(连接超时)\n”}