我正在开发一个Windows Phone 8.1项目.Windows 8.1中有两个版本的http客户端 - system.net.http和windows.web.http.Microsoft建议使用更高版本.
所以,我决定坚持下去.但我找不到取消开始的网页请求的方法windows.web.http.httpclient.在system.net.http.httpclient有一种CancelPendingRequests方法,但为后来的选项中不存在类似的方法.
那么,是否有可能取消网络请求,如果是这样的话?
示例代码:
考虑Http Get谷歌请求如下.如果用户愿意,我想在完成之前取消它.
// Windows Phone 8.1 project (not silverlight)
public sealed partial class MainPage : Page
{
Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient();
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
Windows.Phone.UI.Input.HardwareButtons.BackPressed += (s, e) =>
{
CancelGet();
}
}
private void CancelGet()
{
// What to put here??
// tried client.Dispose();
// but still get request completes successfully
}
private async …Run Code Online (Sandbox Code Playgroud) c# networking windows-store-apps windows-8.1 windows-phone-8.1