2017-09-16 58 views

回答

0

一种方法可能是使用HTTPClient来执行GetAsync()并检查出来的状态码。

根据您的时间限制,您可以等待它自然超时或传递取消标记,以便比默认值更快地分解它。

从这里https://docs.microsoft.com/en-us/windows/uwp/networking/httpclient(略有修改):

//Send the GET request asynchronously and retrieve the response as a string. 

Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage(); 
string httpResponseBody = ""; 

try 
{ 
    //Send the GET request 
    httpResponse = await httpClient.GetAsync(requestUri); 
    if(httpResponse.IsSuccessStatusCode) { /* Do something with it */ } 
    else { /* Do fallback here */ } 
} 
catch (Exception ex) 
{ 
    httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message; 
} 
+0

这是我目前的解决方案已经 - 我认为有可能是一个更优雅的在那里。 – Christoph

相关问题