这不是我第一次使用这种方法发送帖子请求,而且我从来没有遇到过任何问题:
public static Stream SendPostRequest(Uri uri, byte[] postData)
{
var request = WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
return request.GetResponse().GetResponseStream();
}在request.GetRequestStream()上,我得到一个System.Net.WebException:基础连接已关闭:发送时发生意外错误。
更有趣的是,它在某些机器上运行得非常好,但在我的机器(Windows7Beta)和生产服务器(Windows 2008)上却无法工作。更多信息:
作品- Windows .NET 2.0
作品- Windows .NET 3.5
作品- Windows 2003 - .NET 3.0
不起作用- Windows .NET 3.5
不起作用-WindowsServer2008-.NET 3.5
不起作用-Windows7Beta- .NET 3.5 SP1
试过:
解决了。类
我忘了说,但Uri是https.我试过了,成功了。不敢相信,我没早点试过.
不过,我还是会感激的,如果有人能照亮这整个情况。
发布于 2009-03-09 09:24:01
我的第一个攻击计划是使用WireShark来查看每一种情况下在网络级别上发生了什么。看看每台机器都发送了什么。
另外,您已经注意到了操作系统之间的差异,但是它们是否都安装了完全相同版本的.NET (直到SP)?
发布于 2009-03-09 09:33:15
有工作吗?可能是代理配置问题(proxycfg等)。
此外,为了简化事情(减少未知信息的数量),请考虑使用WebClient进行发布:
using (WebClient client = new WebClient())
{
client.Headers.Add("content-type","application/x-www-form-urlencoded");
client.UploadData(address, data);
// or more simply
client.UploadValues(address, nameValuePairs);
}发布于 2009-03-09 12:29:26
尝试调整以下一个或多个选项:
此外,请注意它们与您的不同配置之间的差异。
https://stackoverflow.com/questions/625513
复制相似问题