Change user agent in WP8.1 WebView

2019-01-28 15:12发布

This is for Windows Phone. I'm using windowsphone8.1 update 1. you know that the web interface works like that of android and iOS. How do I get the same interface in my wp8.1 web-apps? I downloaded and installed WP8.1 Update 1 SDK. I don't see Wp8.1 update 1 version to select when I open a new project. Can I get updated web interface in WP8.1 or Cyan updated users?

2条回答
聊天终结者
2楼-- · 2019-01-28 15:25

An alternative in this post https://social.msdn.microsoft.com/Forums/en-US/e7954cf9-88ba-4318-aebf-f528ade5c13d/still-no-way-to-set-ua-string-in-81-webview?forum=w81prevwCsharp answered by _Pete

HttpRequestMessage httpRequestMessage = 
new HttpRequestMessage(HttpMethod.Post, new Uri("website"));
httpRequestMessage.Headers.Append("User-Agent", 
                "Custom User-Agent"); 

webView.NavigateWithHttpRequestMessage(
httpRequestMessage);

Obviously it works for one Uri

查看更多
冷血范
3楼-- · 2019-01-28 15:34

Windows Phone 8.1 Update 1 does not introduce any new public APIs for developers.

If you're working with the WebView (aka the WebBrowser) control in a Windows Phone 8.1 XAML project and you want to specify a different user-agent for the entire session, use...

[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(int dwOption, string pBuffer, int dwBufferLength, int dwReserved);

const int URLMON_OPTION_USERAGENT = 0x10000001;

public void ChangeUserAgent(string Agent)
{
    UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, Agent, Agent.Length, 0);
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    ChangeUserAgent("My Custom User-Agent");
    wb.Navigate(new Uri("http://basquang.wordpress.com/2014/04/26/wp8-1-changing-windows-phone-8-1-webview-default-user-agent-in-all-outbound-http-requests/", UriKind.Absolute));
}

Source: basquang on clouds blog

查看更多
登录 后发表回答