簡體   English   中英

使用 SOAP Web 服務的 HTTPS 請求

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM