webClient.Headers.Add(string key, string value) behaves strange if 'key' has a square bracket in it? ([])
-
Hi there, I came across this strange thing, i don't know how to handle it. Maybe a pretty stupid question or a case of RTFM - but i couldn't find any refference... Following code works just fine:
WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type","application/x-www-form-urlencoded"); webClient.Headers.Add("abc", "123"); byte[] postArray = Encoding.UTF8.GetBytes("submitting some data here..."); byte[] responseArray = webClient.UploadData("MyServer", postArray); Console.WriteLine("Response received was : " + Encoding.ASCII.GetString(responseArray)); Console.Read();
BUT if i change the HTTP Header to something likewebClient.Headers.Add("abc[OBJECT_ID]", "123");
i get an error in the next line (byte[] postArray...) saying: An unhandled exception of type 'System.ArgumentException' occurred in system.dll So it's the square brackets causing the issue. Do i need to escape them in any way??? thanks in advance, - ajs