发送 SOAP 请求

发布于 2024-11-27 05:58:33 字数 794 浏览 0 评论 0原文

在我的应用程序中,我想向某个 url 发送 SOAP 请求,要发送的 SOAP 请求如下

POST /TelLink/WrenchENTService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WrenchGlobal/GetToDoList"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetToDoList xmlns="http://WrenchGlobal/">
    <viPeriod>int</viPeriod>
    <vsUserID>string</vsUserID>
  </GetToDoList>
</soap:Body>
</soap:Envelope>

在上面的代码中,我必须将“int”和“string”替换为实际值,它将调用 GetToDoList服务器。我的问题是,我不知道如何将这个请求发送到服务器? (使用httppost)有人可以帮助我吗?

In my application I want to send a SOAP request to some url, the SOAP request to be sent is as below

POST /TelLink/WrenchENTService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WrenchGlobal/GetToDoList"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetToDoList xmlns="http://WrenchGlobal/">
    <viPeriod>int</viPeriod>
    <vsUserID>string</vsUserID>
  </GetToDoList>
</soap:Body>
</soap:Envelope>

In the above code, I will have to replace "int" and "string" with actual values and it will invoke GetToDoList on the server. My problem is, I dont know how to send this request to the server? (using httppost) Could anyone help me out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明天过后 2024-12-04 05:58:33
int viPeriod;
String vsUserID;
String NAMESPACE = "http://WrenchGlobal/";
String SOAP_ACTION = "http://WrenchGlobal/GetToDoList";
String METHOD_NAME = "GetToDoList";

String result = null;
Object resultRequestSOAP = null;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("viPeriod", viPeriod);
request.addProperty("vsUserID", vsUserID);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

envelope.dotNet = true;
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;

try {
    androidHttpTransport.call(SOAP_ACTION, envelope);

    String requestDumpString = androidHttpTransport.requestDump;
    System.out.println("requestDump : " + requestDumpString);

    resultRequestSOAP = envelope.getResponse(); // Output received
    result = resultRequestSOAP.toString(); // Result string

    System.out.println("OUTPUT : " + result);
} catch (Exception e) {
    e.printStackTrace();
}

希望这会有所帮助。

int viPeriod;
String vsUserID;
String NAMESPACE = "http://WrenchGlobal/";
String SOAP_ACTION = "http://WrenchGlobal/GetToDoList";
String METHOD_NAME = "GetToDoList";

String result = null;
Object resultRequestSOAP = null;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("viPeriod", viPeriod);
request.addProperty("vsUserID", vsUserID);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

envelope.dotNet = true;
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;

try {
    androidHttpTransport.call(SOAP_ACTION, envelope);

    String requestDumpString = androidHttpTransport.requestDump;
    System.out.println("requestDump : " + requestDumpString);

    resultRequestSOAP = envelope.getResponse(); // Output received
    result = resultRequestSOAP.toString(); // Result string

    System.out.println("OUTPUT : " + result);
} catch (Exception e) {
    e.printStackTrace();
}

Hope this would help.

红墙和绿瓦 2024-12-04 05:58:33

IntentService HttpPost 可能是您想要的。谷歌上有很多可用的片段; 这里只是其中之一。

IntentService HttpPost are probably what you want. There are plenty of snippets available on Google; here's just one of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文