对于dotnet中返回404后继续读取http的内容的处理

来源:互联网 发布:apache cxf jar 编辑:程序博客网 时间:2024/05/21 14:54

有的程序在处理返回时会使用404返回出错信息,具体的出错内容会在Http的请求体中出现。对于dotnet缺省是不读取的,需要自己来处理。

 

对于通过http 404来返回错误后,要继续读取http的内容:
catch (WebException webEx)
{
    using (Stream stream = webEx.Response.GetResponseStream())
    {

        using (StreamReader reader = new StreamReader(stream))
        {
            string txt = reader.ReadToEnd();
        }
    }
}

 

 

 

 

0 0