Web客户端提供了错误
问题描述:
我想发布到我们的星号框从控制台应用程序解析出电话清单Web客户端提供了错误
“的现有连接被强行关闭远程主机”这个作品:
class Program
{
static void Main(string[] args)
{
Console.WriteLine(HttpPost());
System.Threading.Thread.Sleep(10000);
}
public static string HttpPost()
{
var URI = @"http://sip.ligmarine.com/admin/config.php?quietmode=on&type=tool&display=printextensions";
var Parameters = "display=printextensions&quietmode=on&type=tool&core=core&featurecodeadmin=featurecodeadmin&paging=paging";
var retVal = "";
WebClient wc = new WebClient();
wc.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("maint:password")));
wc.Headers.Add("referer", @"http://sip.ligmarine.com/admin/config.php?type=tool&display=printextensions");
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
retVal = Convert.ToBase64String(Encoding.ASCII.GetBytes("maint:password"));
//Console.Write("Resulting Request Headers: ");
//Console.WriteLine(wc.Headers.ToString());
byte[] byteArray = Encoding.ASCII.GetBytes(Parameters);
//Console.WriteLine("Uploading to {0} ...", URI);
// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray = wc.UploadData(URI, "POST", byteArray);
// Console.WriteLine("\nResponse received was {0}",);
retVal = Encoding.ASCII.GetString(responseArray);
return retVal;
}
}
从我们的IIS6托管ASP.NET页面,我得到
一个现有的连接被强行远程主机 说明关闭:当前Web的执行过程中发生未处理的异常
请求。请查看堆栈跟踪以获取有关该错误的更多信息,并查看源代码中的错误代码和
。
Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
Line 37: //Console.WriteLine("Uploading to {0} ...", URI);
Line 38: // Upload the input string using the HTTP 1.0 POST method.
Line 39: byte[] responseArray = wc.UploadData(URI, "POST", byteArray);
Line 40: // Console.WriteLine("\nResponse received was {0}",);
Line 41:
的HttpPost方法是完全相同的页面加载:
protected void Page_Load(object sender, EventArgs e)
{
var ret = HttpPost();
Response.Write(ret);
}
答
这是一台DNS问题...服务器被解析为私有IP控制台应用程序是解决公共
答
我的情况非常相似,但解决方案不同。在我的Windows 10开发机器+控制台应用程序上,WebClient.UploadData
到https
地址工作得很好。但是,当相同的确切功能被复制到ASP.NET MVC应用程序,并发布到不同的Web服务器(Windows 2008 R2)时,它会发出以下异常:
System.Net.WebException:底层连接已关闭:在发送时发生意外错误 。 ---> System.IO.IOException: 无法从传输连接读取数据:现有的 连接被远程主机强制关闭。 ---> System.Net.Sockets.SocketException:一个现有的连接 强行远程主机
这两个项目都关闭使用.NET Framework 4.6.1
通过使呼叫使用解决TLS1.2
。只是UploadData
前补充一点:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
有多大,你的文件上传? – volody 2010-05-11 19:20:12
no file ...使用上传数据发布表单数据 – MarkKGreenway 2010-05-11 19:23:55
您是否在iis服务器上配置了任何防火墙 – volody 2010-05-11 19:35:13