Adding Custom HTTP Headers to messages send via HTTP Adapter
There will often be times we need to add some custom HTTP Headers to our outgoing message. The common one we come across is SOAPAction, if you need to communicate with the web services just with HTTP adapter (not using SOAP Adapter).
BizTalk server gives us a context property called “UserHttpHeader” as part of the HTTP adapter, which can be used to set custom HTTP headers.
The below Orchestration shows an example, how you can take advantage of “UserHttpHeader” property.
The code inside the “Message Assignment” shape is shown below:
MSG_AUTHOR_OUT = MSG_AUTHOR_IN;
MSG_AUTHOR_OUT(*) = MSG_AUTHOR_IN(*);
MSG_AUTHOR_OUT(HTTP.UserHttpHeaders) = “userName: helloworld\r\npassword: world”;
Important things to note:
- You can add multiple headers (ex: userName, password) in a single line as shown in the sample above.
- “\r\n” is used to separate multiple headers.
- “: ” is used to separate header and value, you must specify a SPACE after colon.
The content of the output file is shown below
Content-Type: text/xml; charset=utf-16
User-Agent: Microsoft (R) BizTalk (R) Server 2010
<?xml version=”1.0″ encoding=”utf-16″?><<stripped content for clarity>>