[SOLVED] What is difference between HttpResponseMessage.Headers and HttpResponseMessage.Content.Headers

Issue

This Content is from Stack Overflow. Question asked by Ateist

I’m trying to integrate my service with third-party service. The service returns me a file with Content-Type and Content-Disposition headers. I expected the headers will be returned in HttpResponseMessage.Headers, but I got’em in HttpResponseMessage.Content.Headers
Why are some type of headers could be returned in HttpResponseMessage.Headers and some other types in HttpResponseMessage.Content.Headers?

Solution

Request headers and content headers have different purposes.

While request headers carry information about request itself and about client (caller), content headers describe “entity” or its metadata.

Have a look at sample http request:

            POST /some/url HTTP/1.1
            Host: someHost
            User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36
request     Accept: application/json, text/plain, */*
headers     Accept-Encoding: gzip,deflate
            Connection: keep-alive
            Referer: url
            Content-Type: multipart/form-data; boundary=----------564564546545645
            Content-Length: 462560

            ------------564564546545645
content     Content-Disposition: form-data; name="file"; filename="1.png"
headers     Content-Type: image/png

            .PNG
            ......................;
            ------------564564546545645

Answered by Aleksey L.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5.CC BY-SA 3.0.CC BY-SA 4.0.

people found this article helpful. What about you?