簡體   English   中英

Apache httpPost將https更改為url中的http

[英]Apache httpPost change https to http in url

我想用Apache httpclient調用https post方法。 我在互聯網上找不到解決方案。 問題是當我將方法https更改為http時,我不知道為什么嗎?!

我嘗試了很多方法。但所有方法都將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()+"_________________________-")
    }
}

我希望網址不要將https更改為http。 對不起,如果我解釋不好。謝謝

您只需搜索以下內容即可在Web上找到大量示例: apache http client post 無論如何,這應該適合您,具體取決於您使用的版本:

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