[英]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.