【问题标题】:HTTPS Request with SOAP Web Service带有 SOAP Web 服务的 HTTPS 请求
【发布时间】:2017-09-29 01:27:41
【问题描述】:

您好,我想知道如何为肥皂 API 发出 https 请求。

在 Android 应用中,我搜索了很多,但没有明确的教程解释如何做到这一点。

有什么建议或帮助吗?

谢谢

【问题讨论】:

  • 为什么你还想使用 SOAP ?使用 Rest 服务。
  • 我使用 SOAP 的 api 我没有授权将其更改为 rest

标签: java android asp.net-web-api soap-client webservice-client


【解决方案1】:
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 请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 2012-05-13
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    相关资源
    最近更新 更多