GetRequestStream 無法連接到服務器 目標計算機積極拒絕 127.0.0.1 1080
一個下午由於對HttpWebRequest 用得很少原因,折騰了一個晚上
接入正題:在C# 後臺使用HttpWebRequest post數據的時候,提示 無法連接到服務器
最後通過googel https://www.experts-exchange.com/questions/20936810/Error-Unable-to-connect-to-the-remote-server-when-using-GetResponse-or-EndGetResponse.html
具體原因 可參考 https://www.cnblogs.com/AllanDragoon/p/3323370.html
下面貼出我的代碼
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Method = "POST";
webRequest.KeepAlive = false;
using (Stream requestStream = webRequest.GetRequestStream())
{
byte[] paramBytes = Encoding.UTF8.GetBytes(body.ToString());
}
WebResponse webResponse = webRequest.GetResponse();
using (StreamReader myStreamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
{
object reun = myStreamReader.ReadToEnd();
return reun;
}
GetRequestStream 無法連接到服務器 目標計算機積極拒絕 127.0.0.1 1080