a) There is no response.RequestMessage.Headers.ContentType
b) There is no originalRequest.Headers.ContentType
c) Calling response.RequestMessage.Headers.GetValues("Content-Type") gives InvalidOperationException: Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent
objects.
d) Calling originalRequest.Headers.GetValues("Content-Type") gives the same as c)
The header is there, I just don't seem to be able to get to it. Doing a ToString() on the originalRequest shows:
?originalRequest
{Method: POST, RequestUri: 'http://localhost:1354/api/catalog', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
LittleClive
Member
91 Points
65 Posts
DelegatingHandler: Request "Content-Type" throws: Misused header name. Make sure request headers ...
Feb 21, 2012 11:21 AM|LINK
I am trying to read the Content-Type header (specifically a version parameter) in a DelegatingHandler as follows:
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken).ContinueWith(
task =>
{
HttpResponseMessage response = task.Result;
HttpRequestMessage originalRequest = request;
I'm finding
a) There is no response.RequestMessage.Headers.ContentType
b) There is no originalRequest.Headers.ContentType
c) Calling response.RequestMessage.Headers.GetValues("Content-Type") gives InvalidOperationException: Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
d) Calling originalRequest.Headers.GetValues("Content-Type") gives the same as c)
The header is there, I just don't seem to be able to get to it. Doing a ToString() on the originalRequest shows:
?originalRequest
{Method: POST, RequestUri: 'http://localhost:1354/api/catalog', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Host: localhost:1354
User-Agent: Fiddler
Content-Length: 34
Content-Type: application/vnd.myapp.api+json; version=3.0
Kiran Challa
Participant
1442 Points
281 Posts
Microsoft
Re: DelegatingHandler: Request "Content-Type" throws: Misused header name. Make sure request head...
Feb 21, 2012 03:48 PM|LINK
Can you try the following to see if you are able to access the content-type header:
"response.RequestMessage.Content.Headers.ContentType"
Kiran Challa
LittleClive
Member
91 Points
65 Posts
Re: DelegatingHandler: Request "Content-Type" throws: Misused header name. Make sure request head...
Feb 21, 2012 04:28 PM|LINK
Cool that worked - thanks!