I have a C# WCF service that receives a request Message and post it to another service.
Posting to the other service is done through HttpWebRequest.
How can i get in my service the original request HTTP headers and put them in the HttpWebRequest when i post them to the other service.
Something like this:
HttpRequestMessageProperty httpRequestProp = GetHttpRequestProp(requestMessage);
HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(uri);
foreach (var item in httpRequestProp.Headers.AllKeys)
{
loHttp.Headers.Add(item, httpRequestProp.Headers[item]);
}
I know this doesn’t work because HttpWebRequest loHttp has its own properties, and when i try to set ContentType for example in the above way it throws exception because it needs to be set like this:
loHttp.ContentType = httpRequestProp.Headers[HttpRequestHeader.ContentType];
So is there a way to copy the HTTP request headers from a call and put them as HTTP request headers to another HttpWebRequest ? Also the original request might have other custom headers set and i want send those also to the other service.
Thank you,
Adrya
You can get the headers via
You can set the headers via
Example:
However, understand that some headers are restricted, and cannot be modified freely. These are:
I suppose you should look, case by case, which headers you can/want to replicate from the incoming call to the outgoing one.