Reputation: 2901
I'm building a http request in my c# client and and want to append an If-Match
header. To get that If-Match header, I'm using this object which comes from System.Net
:
var headerkey = HttpRequestHeader.IfMatch.ToString();
I would expect calling toString on this to output: If-Match
however, instead I'm getting IfMatch
which is not a valid http header. Is there a way I can get the correct value without hardcoding a string in my code that looks like this:
const string ifMatch = "If-Match";
Upvotes: 0
Views: 895
Reputation: 896
You can use the code below, and it will generate the headers that you need based on those enums, instead of performing a ToString on an enum
var request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
var headers = request.Headers;
headers.Add(HttpRequestHeader.IfMatch, "NameHere")
Upvotes: 1