Change user agent in WP8.1 WebView

匆匆过客 提交于 2019-12-18 09:18:13

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/25228722/change-user-agent-in-wp8-1-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!