在WP8.1 WebView中更改用户代理
这适用于Windows Phone。 我正在使用windowsphone8.1更新1.您知道Web界面的工作方式与Android和iOS相同。 如何在我的wp8.1网络应用程序中获得相同的界面? 我下载并安装了WP8.1 Update 1 SDK。 我没有看到Wp8.1 update 1版本在我打开一个新项目时选择。 我可以在WP8.1或Cyan更新的用户中获得更新的Web界面吗?
Windows Phone 8.1 Update 1不为开发人员引入任何新的公共API。
如果您正在使用Windows Phone 8.1 XAML项目中的WebView
(也称为WebBrowser
)控件,并且要为整个会话指定其他用户代理,请使用…
[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)); }
来源: basquang on clouds blog
这篇文章的另一个选择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由_Pete回答
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri("website")); httpRequestMessage.Headers.Append("User-Agent", "Custom User-Agent"); webView.NavigateWithHttpRequestMessage( httpRequestMessage);
显然它适用于一个Uri