gpt4 book ai didi

java - 如果端点是 https,是否使用 HTTPS

转载 作者:行者123 更新时间:2023-12-02 11:21:40 26 4
gpt4 key购买 nike

我有一个可以向端点发出 SOAP 请求的客户端。端点以 https 开头,但客户端中不使用 HttpsURLConnection。我想问一下,由于端点是https,SOAP请求是否仍会使用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);

最佳答案

事实上,如果其 URL 以 https 开头,则它会执行 HTTPSURLConnection 操作,无需特别指定。

If URL= https://someexample.org //its by default HTTPSURLConnection

If URL=http://someexample.org //its by default 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);

关于java - 如果端点是 https,是否使用 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49879652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com