thomasmartinsen
thomasmartinsen

Reputation: 1993

Custom USER-AGENT in UWP WebView

I'm working on a UWP app and have a page with a WebView. In the WebView I need to set the user-agent to a custom value.

I have tried the following:

var requestMessage = new HttpRequestMessage(HttpMethod.Get, baseUri);
requestMessage.Headers.Add("User-Agent", "MyCustomValue");
webview.NavigateWithHttpRequestMessage(requestMessage);

However the WebView doesn't use my custom user-agent but instead use the original default value of the user-agent. This is confirmed by this thread at MSDN.

Any good input to alternative solutions or workarounds is appreciated.

Upvotes: 2

Views: 2003

Answers (2)

Dmytro Bondarenko
Dmytro Bondarenko

Reputation: 1022

Try it:

var rm = new Windows.Web.Http.HttpRequestMessage(HttpMethod.Get, new Uri("https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending")); 
rm.Headers.Add("User-Agent", "test");
rm.Headers.Add("NSASESSIONID", "CA79AB9B-21CD-43BE-A48A-49B5F1289D22");
WebView.NavigateWithHttpRequestMessage(rm);

It's working for me.

Upvotes: 1

Martin Esmann
Martin Esmann

Reputation: 154

It seems only to be supported when doing POST, not GET.

Perhaps this blog post can get you closer to a solution: https://basquang.wordpress.com/2014/04/26/wp8-1-changing-windows-phone-8-1-webview-default-user-agent-in-all-outbound-http-requests/

Upvotes: 1

Related Questions