I can set Request.Content-Type = ... , Request.Content-Length = ...
How to set Accept and Accept-Language?
I want to upload a file (RFC 1867) and need to create a request like this:
POST /test-upload.php.xml HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Content-Type: multipart/form-data; boundary=---------------------------21724139663430 Content-Length: 56048
I have to confirm after several annoying attempts to use the headers that the
myWebHeaderCollection.Add("foo","bar");
solution works perfectly.if you want to set the Language.
Does not set the values however. Which may seem like a logical conclusion given the first one works.
If you are using HttpRequestMessage, set the header using Headers.Add method. In your case :
When you want to set the Accept type and content type, just cast the webrequest to HttpwebRequest
Take a look at Accept property:
This MSDN article shows how to add custom headers to your request:
You need to be sure that you type cast the request to (HttpWebRequest), where the accept header property is available.
In the old WebRequest class, the Accept header is not accessible.