Reputation: 867
When inspecting a third party api using chrome browser's F12 tool I found there are several interesting headers listed:
:authority:m.somedomain.com
:method:GET
:path:/api/somevalues
:scheme:https
Along with some headers I'm familiar with, such as accept, accept-encoding, etc.
I'm using .Net 4.0 to make http/https requests. When trying to add these headers starting with a colon, an error is thrown on the first item:
httpRequest.Headers.Add(":authority", "m.somedomain.com");
httpRequest.Headers.Add(":method", "get");
httpRequest.Headers.Add(":path", sPath);
httpRequest.Headers.Add(":scheme", "https");
Error message:
Specified value has invalid HTTP Header characters.
After some searching I found article talking about http/2. However in .NET 4.0 there are only http/1.0 and http/1.1 available.
Does that mean I need to upgrade to newer .NET version?
Thanks in advance.
Upvotes: 1
Views: 1424
Reputation: 2446
Possibly. http/2 is supported from .NET version 4.6.2.
Click on the Project tab and select properties at the bottom. And then change your .NET version to 4.6.2.
Also I am 99.9% sure that you shouldn't include semi colon in your headers.
Further:
httpRequest.Headers.Add(":method", "get");
The request-method should not be defined in the header. Do it like so.
httpRequest.Method = "GET";
The scheme is usually indicated by the prefix of your url. ie:
string webAddr = "https://www.google.com/";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
Upvotes: 1