[英]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.