how to set soap Header using ksoap2 - android

后端 未结 2 1313
耶瑟儿~
耶瑟儿~ 2020-11-27 17:58

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 so

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 18:49

    I did that this way:

    import org.kxml2.kdom.Element;
    

    then while preparing envelope

    soapEnvelope.headerOut = new Element[1];
    soapEnvelope.headerOut[0] = buildAuthHeader();
    // ...send request...
    

    with

    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.

提交回复
热议问题