标签:create targe stream alt method mic question The url
一个下午由于对HttpWebRequest 用得很少原因,折腾了一个晚上
接入正题:在C# 后台使用HttpWebRequest post数据的时候,提示 无法连接到服务器
具体原因 可参考 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());
requestStream.Write(paramBytes, 0, paramBytes.Length);
}
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
标签:create targe stream alt method mic question The url
原文地址:https://www.cnblogs.com/-bao/p/10714328.html