How to pass Authentication Header to node-soap

纵饮孤独 提交于 2019-12-23 03:11:17

问题


I am trying to use a wsdl service as a client but I cannot find how to set some headers.

The reason I need this is because the wsdl I am trying to use requires the username and password via the headers. this is wsdl

>    POST /Service.asmx HTTP/1.1
>             Host: 210.12.155.16
>             Content-Type: text/xml; charset=utf-8
>             Content-Length: length
>             SOAPAction: "http://yyyy.com:1002/apability"
>             
>             <?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:Header>
>                 <AuthHeader xmlns="http://yyyy.com:1002/">
>                   <UserName>string</UserName>
>                   <Password>string</Password>
>                 </AuthHeader>
>               </soap:Header>
>               <soap:Body>
>                 <sale xmlns="http://yyyy.com:1002/">
>                   <BID>string</BID>
>                   <Amount>string</Amount>
>                   </sale>
>               </soap:Body>
>             </soap:Envelope>

and this is code :

   var args={BID:"123",Amount : "10000"};

      var AuthHeader = {
                "UserName" : user,
                "Password" : pass
                };
            soap.createClient(url,function(error,client){
            client.addSoapHeader(AuthHeader);   

              client.sale(args,function(error,result){
              console.log(error);

            });

i have to send authentication in header but it doesn't work
i thing soapHeader's var is wrong . what would i do to solve authentication problem ? thanks a lot


回答1:


You can less try sending your header in this way

var Autentication ='<AuthHeader xmlns="http://yyyy.com:1002/"><UserName>user</UserName><Password>pass</Password></AuthHeader>'

Add header

client.addSoapHeader(Autentication)

Good Luck




回答2:


i found answer

var AuthHeader = {AuthHeader: {
            "UserName" : user,
            "Password" : pass,

            }


来源:https://stackoverflow.com/questions/30829121/how-to-pass-authentication-header-to-node-soap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!