How to Set Custom User Agent for a WebView in Windows 10 ?

When working with the WebView in Universal Windows Platform app , there are times when you want to pass a custom user agent along with the request.

The WebView in Windows 10 includes a method called NavigateWithHttpRequestMessage which lets you pass the object of type HttpRequestMessage. We could use the Header property of the HttpRequestMessage and set the user agent of the request as shown below.

How to Set Custom User Agent for a WebView in Windows 10 ?

var httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Get, new Uri("http://DeveloperPublish.com"));
httpRequestMessage.Headers.Add("User-Agent", "DeveloperPublishUserAgent");
webView1.NavigateWithHttpRequestMessage(httpRequestMessage);

One Response

  1. Filipe August 13, 2016 Reply

Leave a Reply