How to constantly change user agent on a Windows phone?

I want to change the user agent of my webbrowser control. I can do it:

webbrowserTest.Navigate(new Uri("http://mywebsite.com"), null, "User-Agent: myuseragent"); 

The problem is that the user agent will be valid for only one request, and not for a subquery or redirect. How to constantly change this user agent?

+4
source share
1 answer

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.

-1
source

All Articles