編輯
你可以聽NavigationStarting事件
public MainPage()
{
this.InitializeComponent();
MyWebView.NavigationStarting += MyWebViewOnNavigationStarting;
}
private void MyWebViewOnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
string navigatingUri = args.Uri.ToString();
}
注意,這只是web視圖內捕獲導航事件。
原始 「錯誤」 的答案
- 將在
Asset
文件夾中的HTML文件
- 在Web視圖,把
Source
與ms-appx-web:///Assets/{htmlFileName}
<WebView x:Name="MyWebView" Source="ms-appx-web:///Assets/Foo.html"></WebView>
或通過代碼
public MainPage()
{
this.InitializeComponent();
MyWebView.Navigate(new Uri("ms-appx-web:///Assets/Foo.html"));
}
來源
2017-02-23 06:01:30
Bob
你想充當一個網絡服務器? – DavidG
[在C#中攔截由WebBrowser發出的請求]的可能重複(http://stackoverflow.com/questions/811587/intercepting-requests-made-by-webbrowser-in-c-sharp) – Gusman
不,我想要捕捉請求並返回沒有Web服務器的響應。 – pipikapu