简体   繁体   English

Apache httpPost将https更改为url中的http

[英]Apache httpPost change https to http in url

i want to call https post method with apache httpclient. 我想用Apache httpclient调用https post方法。 i dont find solution in internet. 我在互联网上找不到解决方案。 the problem is when i call method https change to http and i dont know why?! 问题是当我将方法https更改为http时,我不知道为什么吗?!

i tried many ways.but all of them change https to http in url. 我尝试了很多方法。但所有方法都将https更改为url中的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()+"_________________________-")
    }
}

i expect url dont change https to http. 我希望网址不要将https更改为http。 sorry if i explain it bad.thanks 对不起,如果我解释不好。谢谢

You can find plenty of examples on the Web just by searching for: apache http client post . 您只需搜索以下内容即可在Web上找到大量示例: apache http client post In any case, this should work for you, depending on the version you are using: 无论如何,这应该适合您,具体取决于您使用的版本:

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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM