简体   繁体   English

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

[英]Change user agent in WP8.1 WebView

This is for Windows Phone.这适用于 Windows Phone。 I'm using windowsphone8.1 update 1. you know that the web interface works like that of android and iOS.我正在使用 windowsphone8.1 更新 1。您知道 Web 界面的工作方式类似于 android 和 iOS。 How do I get the same interface in my wp8.1 web-apps?如何在我的 wp8.1 网络应用程序中获得相同的界面? I downloaded and installed WP8.1 Update 1 SDK.我下载并安装了 WP8.1 Update 1 SDK。 I don't see Wp8.1 update 1 version to select when I open a new project.当我打开一个新项目时,我没有看到 Wp8.1 update 1 版本可供选择。 Can I get updated web interface in WP8.1 or Cyan updated users?我可以在 WP8.1 或青色更新用户中获得更新的 Web 界面吗?

Windows Phone 8.1 Update 1 does not introduce any new public APIs for developers. Windows Phone 8.1 Update 1 没有为开发人员引入任何新的公共 API。

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...如果您在 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));
}

Source: basquang on clouds blog来源: basquang 上云博客

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

Obviously it works for one Uri显然它适用于一个 Uri

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

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