【问题标题】:Is HTTPS used if the end point is a https如果端点是 https,则使用 HTTPS
【发布时间】:2018-04-17 13:38:02
【问题描述】:

我有一个可以向端点发出 SOAP 请求的客户端。端点以https 开头,但在客户端中没有使用HttpsURLConnection。我想问下SOAP请求是否还会因为端点是https而使用TLS发送?

客户端实现:

String endPoint = "https://some_endpoint";

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

SOAPMessage soapRequest = //create the soap req.
SOAPMessage soapResponse = soapConnection.call( soapRequest, endPoint); 

【问题讨论】:

  • 当协议为https: 时,是否有任何理由假设SOAPConnection 不使用HttpsURLConnection

标签: java soap java-8 soap-client tls1.2


【解决方案1】:

其实HTTPSURLConnection如果它的URL在后台以https开头,不需要特别指定。

如果 URL= https://someexample.org //默认为 HTTPSURLConnection

如果 URL=http://someexample.org //默认为 HTTPURLConnection

使用下面的代码来证明它确实在幕后工作。

使用 http URL 在下面执行一次,然后再次使用 https URL 执行相同的代码。在这两种情况下,它的工作原理都是一样的。这意味着,它在后台执行 HTTPSURLConnection。

    String endPoint = "https://someURL.mockable.io";

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    String soapString = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\" "
            + "soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\"><soap:Body xmlns:m=\"http://www.example.org/stock\">"
            + "<m:GetStockPriceResponse><m:Price>34.5</m:Price></m:GetStockPriceResponse></soap:Body></soap:Envelope>";


    InputStream is = new ByteArrayInputStream(soapString.getBytes());

    SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

    SOAPMessage soapResponse = soapConnection.call(request, endPoint);
    System.out.println(soapResponse);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 2016-09-09
    • 2019-08-08
    • 2011-07-23
    • 1970-01-01
    相关资源
    最近更新 更多