如何使用 ksoap2 设置soap Header - android [英] how to set soap Header using ksoap2 - android
本文介绍了如何使用 ksoap2 设置soap Header - android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将soap 标头信息设置为Web 方法身份验证的一部分.我正在使用 ksoap2 API 来调用 .NET Web 服务.这是带有请求的soap 标头.
I need to set the soap header information as part of authentication of a web method. I'm using ksoap2 API to call .NET web service. Here is the soap header with request.
<soap:Header>
<DTHeader xmlns="http://myServer.com/webservices/">
<Username> string </Username>
<Password> string </Password>
</DTHeader>
</soap:Header>
<soap:Body>
<MyTestMethod xmlns="http://myServer.com/webservices/">
<ID> string </ID>
<TransID> guid </TransID>
</MyTestMethod>
</soap:Body>
你能提供android代码来设置soap头DTHeader"并设置用户名"和密码".
Can you please provide the android code to set the soap header "DTHeader" and set "Username" and "Password".
推荐答案
我是这样做的:
import org.kxml2.kdom.Element;
然后在准备信封时
soapEnvelope.headerOut = new Element[1];
soapEnvelope.headerOut[0] = buildAuthHeader();
// ...send request...
与
private Element buildAuthHeader() {
Element h = new Element().createElement(NAMESPACE, "AuthHeader");
Element username = new Element().createElement(NAMESPACE, "user");
username.addChild(Node.TEXT, USERNAME);
h.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(NAMESPACE, "pass");
pass.addChild(Node.TEXT, PASSWORD);
h.addChild(Node.ELEMENT, pass);
return h;
}
显然,根据需要更改字符串.
obviously, change strings as needed.
这篇关于如何使用 ksoap2 设置soap Header - android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文