簡體   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