如何将Authentication Header传递给node-soap

时间:2015-06-14 12:02:38

标签: xml node.js http-headers node-soap

我正在尝试将wsdl服务用作客户端,但我找不到如何设置一些标头。

我需要这个的原因是因为我尝试使用的wsdl需要通过标头的用户名和密码。 这是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>

这是代码:

   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);

            });

我必须在标头中发送身份验证 但它没有工作 我认为soapHeader的var是错误的。 我该怎么做才能解决身份验证问题? 非常感谢

2 个答案:

答案 0 :(得分:2)

您可以尝试以这种方式发送标题

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

添加标题

client.addSoapHeader(Autentication)

祝你好运

答案 1 :(得分:0)

我找到了答案

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

            }