【问题标题】:Error getting response stream (ReadDone2): ReceiveFailure获取响应流 (ReadDone2) 时出错:ReceiveFailure
【发布时间】:2015-09-18 04:27:50
【问题描述】:

我正在使用以下代码从实时服务器获取数据...

try
            {
    var httpReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(url_builder.ToString()));
                httpReq.BeginGetResponse((ar) =>
                {
                        var request = (HttpWebRequest)ar.AsyncState;

                        using (var response = (HttpWebResponse)request.EndGetResponse(ar))
                        {

                            //Enter Code here............................

                            response.Close();
                        }
                });
                }, httpReq);
 }
            catch (Exception ex)
            {
                Global.EmailExceptionMessage(ex);
            }

并获得内部异常,即

内部异常:在 System.Net.WebConnection.HandleError(WebExceptionStatus st, System.Exception e, System.String where) 在 System.Net.WebConnection.ReadDone(IAsyncResult 结果)

【问题讨论】:

  • InnerException 上的实际消息是什么?

标签: android asp.net xamarin httpwebrequest httpwebresponse


【解决方案1】:

你可以试试这个代码来获取httpresponse。

HttpWebRequest request = WebRequest.Create("http://google.com") as HttpWebRequest;

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        WebHeaderCollection header = response.Headers;
        var encoding = ASCIIEncoding.ASCII;
        using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
        {
            string responseText = reader.ReadToEnd();
        }

【讨论】:

  • 好的@Umesh Sehta你的代码很好,但我想知道我的代码有什么问题,因为它有时会发出异常,有时它工作正常.....如果你有请帮助我使用我的代码的解决方案...
  • 实际问题是代码在 10 次中有 9 次运行良好,只有 1 次给我异常.....@Umesh Sehta
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
  • 1970-01-01
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
  • 1970-01-01
  • 2021-06-17
相关资源
最近更新 更多