tiaguinho / gosoap

🦉SOAP package for Go
MIT License
508 stars 176 forks source link

Unable to prepare a soap request which require Authheader #49

Open mayur2011 opened 4 years ago

mayur2011 commented 4 years ago

Please Help me setup below SOAP request xml which contains AuthHeader also.

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:out="http://Demo.Manufacturing.Webservices/Outbound/">
                   <soapenv:Header>
                       <out:AuthHeader>
                           <out:UserName>admin</out:UserName>
                         <out:Password>7338b6c1702d</out:Password>
                          </out:AuthHeader>
                      </soapenv:Header>
                      <soapenv:Body>
                            <out:GetOrder>
                            <out:bu>1</out:bu>
                            <out:order>5582</out:order>
                          </out:GetOrder>
                     </soapenv:Body>
           </soapenv:Envelope>
jamesdube commented 3 years ago

Hey :wave:

I was faced with the same problem and here's how I managed to solve it:


    httpClient := &http.Client{
        Timeout: 5 * time.Second,
    }

    soap, err := gosoap.SoapClient("http://some/fancy/location.wsdl", httpClient)
    if err != nil {
        log.Fatalf("SoapClient error: %s", err)
    }

   //set your auth headers here
    soap.HeaderParams = gosoap.HeaderParams{
        "AuthHeader" : map[string]interface{}{
        "Username" : "admin",
        "Password" : "7338b6c1702d",
    },
    }

   //execute request
   // _, err = soap.Call("SomeAction", params)

This is in reference to #8 .

I hope its not too late, cheers

rose-tmp commented 2 years ago

thanks