【发布时间】:2010-12-10 19:36:25
【问题描述】:
我们目前在读取过去没有问题的 ResponseStream 时遇到问题。自从昨晚将 .NET 4.0 Framwework 添加到我们的服务器并分配 IIS 以使用新框架后,我们在尝试使用以下语句读取 responseStream 时遇到了一些不同的异常 (responseStream = httpResponse.GetResponseStream();)。到目前为止,一切都很好。因此,我正在寻找有关如何从响应中读取的更改/改进。我在下面粘贴了我们正在使用的代码以及我们遇到的异常。
我们的环境是:
.NET 框架 4.0 视窗服务器 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();
}
例外情况:
'httpResponse.GetResponseStream().Length' 抛出了一个类型为 'System.NotSupportedException' long {System.NotSupportedException}的异常
'httpResponse.GetResponseStream().Position' 抛出了一个类型为'System.NotSupportedException' long {System.NotSupportedException}的异常
{“此流不支持搜索操作。”} System.SystemException {System.NotSupportedException}
问候,
迈克
【问题讨论】:
-
好吧,我不确定它是否是您的问题的原因,但您正在使用 Method="POST" 而不发送任何数据。我想你可能想要“GET”
标签: c# .net-4.0 httpwebresponse