Change user agent in WP8.1 WebView

后端 未结 2 1721
旧巷少年郎
旧巷少年郎 2020-12-21 18:07

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

相关标签:
2条回答
  • 2020-12-21 18:35

    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

    0 讨论(0)
  • 2020-12-21 18:46

    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

    0 讨论(0)
提交回复
热议问题