'Add HTTP headers to SOAP web service

I am using Web service consumer in Mule4 and I need to pass http header for passing Authentication details to the SOAP service, in Web service consumer there is headers section but it is for SOAP headers, but I could not find how to add HTTP headers.

Did anyone face similar issue.



Solution 1:[1]

It is literally in the documentation: https://docs.mulesoft.com/web-service-consumer-connector/1.6/web-service-consumer-config-topics#configure-custom-http-transport

By default the Web Service Consumer uses its own HTTP Request configuration. You can explicitly configure it to use your own HTTP Request configuration, in which you can define HTTP built-in authorization options, like HTTP Basic Authentication, custom HTTP headers, or any other HTTP Request configurations (like HTTPS options).

Example:

<http:request-config name="basic-auth">
    <http:request-connection host="www.exampleplace.com" port="8182" protocol="HTTP">
        <http:authentication>
            <http:basic-authentication username="admin" password="textpassword"/>
        </http:authentication>
    </http:request-connection>
</http:request-config>

<wsc:config name="with-custom-transport">
    <wsc:connection wsdlLocation="http://www.host.com?WSDL" service="Service" port="Port">
        <wsc:custom-transport-configuration>
            <wsc:http-transport-configuration requesterConfig="basic-auth"/>
        </wsc:custom-transport-configuration>
    </wsc:connection>
</wsc:config>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1