![](/img/trans.png)
[英]SOAP Web service need to send request using https protocol in java
[英]HTTPS Request with SOAP Web Service
您好,我想知道如何為soap API 發出https 請求。
在 Android 應用程序中,我搜索了很多,但沒有明確的教程解釋如何做到這一點。
請問有什么建議或幫助嗎?
謝謝
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
public class HttpsClient {
public static void main(String[] args) throws Exception {
String httpsURL = "https://postman-echo.com/post";
URL myUrl = new URL(httpsURL);
HttpURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.append("<xml><body>your SAOP request here</body></xml>");
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
System.out.println("Response code is : "+conn.getResponseCode());
System.out.print("Response text is :");
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
}
out.flush();
out.close();
br.close();
}
}
SOAP 請求也是請求正文中帶有 xml 的 http POST。 您需要將 url 更改為 Web 服務端點 url,並將示例字符串替換為您的 SOAP 請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.