Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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
C# HttpClient,catch无法连接_C#_Httpclient_Asynchttpclient - Fatal编程技术网

C# HttpClient,catch无法连接

C# HttpClient,catch无法连接,c#,httpclient,asynchttpclient,C#,Httpclient,Asynchttpclient,我有以下代码: ProgressMessageHandler progress = new ProgressMessageHandler(); progress.HttpSendProgress += new EventHandler<HttpProgressEventArgs>(HttpSendProgress); HttpRequestMessage message = new HttpRequestMessage();

我有以下代码:

        ProgressMessageHandler progress = new ProgressMessageHandler();
        progress.HttpSendProgress += new EventHandler<HttpProgressEventArgs>(HttpSendProgress);
        HttpRequestMessage message = new HttpRequestMessage();
        message.Method = HttpMethod.Post;
        message.Content = content;
        message.RequestUri = new Uri("http://myaddress");
        var client = HttpClientFactory.Create(progress);
        sending = client.SendAsync(message);


    private void HttpSendProgress(object sender, HttpProgressEventArgs e)
    {
         //....
    }
我想抓住一个情况,当我的地址不可用时。方法HttpSendProgress在progress处于活动状态时被调用,因此,我无法签入此方法。
任何检查myaddress是否可用的方法。我想再启动一个线程来检查上次何时调用HttpSendProgress。但是可能有一个标准的方法吗?

我认为您无法在进度事件中检查该地址是否为工作地址。您需要在响应返回后检查状态

    if (response.IsSuccessStatusCode)
    {
        Console.WriteLine(response.StatusCode.ToString());
    }

回应是不会回来的。它等待无限时间:您设置了超时吗?client.Timeout=Timespan.fromsseconds30。这将在30秒后回复