来自Asp.net的WebClient给出“远程主机强行关闭了现有连接".错误 [英] WebClient from Asp.net gives "An existing connection was forcibly closed by the remote host" Error

查看:128
本文介绍了来自Asp.net的WebClient给出“远程主机强行关闭了现有连接".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在星号框中发布电话列表,以解析出电话列表

I am trying to post to our asterisk box to parse out the phone list

在控制台应用程序中有效:

from a console application this works :

 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页面获得

from our IIS6 Hosted ASP.NET page I get

现有连接被远程主机强行关闭 说明:执行当前Web期间发生未处理的异常
要求.请查看堆栈跟踪,以获取有关错误和
的更多信息. 它起源于代码的位置.

An existing connection was forcibly closed by the remote host Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.

 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方法与页面加载完全相同:

The HttpPost Method is exactly Identical the page load :

protected void Page_Load(object sender, EventArgs e)
{

    var ret = HttpPost();
    Response.Write(ret);
}

推荐答案

这是一个dns问题...服务器正在解析为私有ip控制台应用程序,正在解析为公开的

It was a dns issue ... the server was resolving to the private ip console app was resolving to public

这篇关于来自Asp.net的WebClient给出“远程主机强行关闭了现有连接".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆