我有一个可以向端点发出SOAP请求的客户端。结束点以https
开头,但客户端中不使用HttpsURLConnection
。我想问一下,由于端点是https?
客户端实施:
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);
答案 0 :(得分:1)
事实上,如果其网址以https开头,则 HTTPSURLConnection ,无需专门指定。
如果网址= 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);