小编Rhi*_*ino的帖子

从HttpWebResponse和.NET 4.0 Framework中读取的正确方法

我们目前在阅读我们过去没有遇到任何问题的ResponseStream时遇到问题.自从昨晚将.NET 4.0 Framwework添加到我们的服务器并分配IIS以使用新框架后,我们在尝试使用以下语句(responseStream = httpResponse.GetResponseStream();)尝试读取responseStream时遇到了一些不同的异常.到目前为止,一切都完美无缺.所以,我正在寻找有关如何从响应中读取的更改/改进.我已经粘贴了我们正在使用的以下代码以及我们遇到的例外情况.

我们的环境是:

.NET Framework 4.0 Windows Server 2003

代码:

        HttpWebResponse httpResponse;
        Stream responseStream;
        //Accept All Certificate Policy 
        ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(new Uri(theUrl));
        httpRequest.Method = "POST";
        httpRequest.KeepAlive = false;
        httpRequest.Timeout = timeOut;


        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            responseStream = httpResponse.GetResponseStream();
        }
Run Code Online (Sandbox Code Playgroud)

例外情况:

'httpResponse.GetResponseStream().Length'抛出类型'System.NotSupportedException'的异常long {System.NotSupportedException}

'httpResponse.GetResponseStream().Position'抛出类型'System.NotSupportedException'的异常long {System.NotSupportedException}

{"此流不支持搜索操作."} System.SystemException {System.NotSupportedException}


问候,

麦克风

c# .net-4.0 httpwebresponse

3
推荐指数
1
解决办法
5711
查看次数

标签 统计

.net-4.0 ×1

c# ×1

httpwebresponse ×1