since it closed the class, I donβt think there is any way to intercept the creation of HttpRequest, and I would have avoided such thinking altogether, since later on you may have other requests that do not require the UserAgent / other header. The easiest thing to do here is probably to create an extension method in a separate static class, for example:
public static class WebBrowserExtensions { public static void NavigateWithUserAgent(this WebBrowser webBrowser, Uri uri) { webBrowser.Navigate(uri, null, "User-Agent: myuseragent"); } }
And then just call:
new WebBrowser().NavigateWithUserAgent(new Uri("http://mywebsite.com"));
Hope this helps.
source share