繁体   English   中英

在 WP8.1 WebView 中更改用户代理

[英]Change user agent in WP8.1 WebView

这适用于 Windows Phone。 我正在使用 windowsphone8.1 更新 1。您知道 Web 界面的工作方式类似于 android 和 iOS。 如何在我的 wp8.1 网络应用程序中获得相同的界面? 我下载并安装了 WP8.1 Update 1 SDK。 当我打开一个新项目时,我没有看到 Wp8.1 update 1 版本可供选择。 我可以在 WP8.1 或青色更新用户中获得更新的 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 上云博客

这篇文章中的另一种选择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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM