[英]C# HttpWebRequest.GetRequestStream() dies when using Proxy
我有以下代码:
HttpWebRequest request = createRequest("http://somesite", true);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("Accept-Encoding", "gzip, deflate");
request.Proxy = new WebProxy("what:ever");
string postData = "my data";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
using (var dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Flush();
}
当我要求VS中断优先机会CLR异常时,request.GetRequestStream()在内部抛出NullReferenceException,然后在我的代码中抛出System.Net.WebException(超时)异常。
当我禁用代理(直接工作)时,它可以工作。
它可以在我家里的电脑上正常工作,但在这里不能正常工作(出租公寓,不同的互联网连接)。
我在两台计算机上使用相同的设置。 找不到任何东西。
谢谢。
好了,将实现更改为使用WebClient.UploadData似乎可以解决问题。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.