WinRT WebView with Custom User-Agent

Saw a conversation on Twitter about this and thought I’d post a quick snippet. If you want to open a website in a WebView control with a fake User Agent, here’s the code to do so:

HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("http://facebook.com"));

httpRequestMessage.Headers.Append("User-Agent", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 ");

webView.NavigateWithHttpRequestMessage(httpRequestMessage);

Leave a comment