Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何超时web调用以检索JSON提要?_Json_Httpclient - Fatal编程技术网

如何超时web调用以检索JSON提要?

如何超时web调用以检索JSON提要?,json,httpclient,Json,Httpclient,我正在使用HttpClient调用以检索JSON提要。我想为这个电话设定一个暂停时间,以防时间太长。如何执行此操作?HttpClient具有Timeout属性。将其设置为所需的超时,并处理TimeoutException以在超时时执行特定操作 HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromSeconds(5); HttpResponseMessage response = null; try {     r

我正在使用HttpClient调用以检索JSON提要。我想为这个电话设定一个暂停时间,以防时间太长。如何执行此操作?

HttpClient具有
Timeout
属性。将其设置为所需的超时,并处理
TimeoutException
以在超时时执行特定操作

HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);
HttpResponseMessage response = null;
try
{
    response = await client.GetAsync(url);
}
catch (TimeoutException)
{
    // handle the timeout, e.g. return false
    return false;
}
catch (Exception ex)
{
    // handle the other errors, e.g. throw it
    throw (ex);
}

据我所知,您想要设置web服务调用的超时时间?您谈论的是响应aur请求的时间?