I've made a little helper function to deal with my HTTP requests that simply takes a string URL and a string array of headers formatted as Header-Name: Value
public static HttpWebResponse MakeHttpRequest(string URL, string[] Headers)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
req.Headers.Clear();
foreach (string h in Headers)
{
var s = h.Split(new char[] { ':' }, 2);
req.Headers.Set(s[0], s[1]);
}
return (HttpWebResponse)req.GetResponse();
}
But if the Headers array contains a Restricted header (e.g User-Agent, or Content-Type, or Accept, etc..) I get an exception telling me to modify the header using its property or method, so I was thinking maybe there was some way to check if any of the Headers was restricted and automatically modify it using its property, unfortunately, I'm not too smart so I don't really know how to do that without having a lot of bloated code checking every single restricted header and having different code run for each one Im guessing it can be done with Reflection but I'm not sure... Help?
Aucun commentaire:
Enregistrer un commentaire