2010-05-11 133 views
2

我想發佈到我們的星號框從控制檯應用程序解析出電話清單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); 
} 
+0

有多大,你的文件上傳? – volody 2010-05-11 19:20:12

+0

no file ...使用上傳數據發佈表單數據 – MarkKGreenway 2010-05-11 19:23:55

+1

您是否在iis服務器上配置了任何防火牆 – volody 2010-05-11 19:35:13

回答

1

這是一臺DNS問題...服務器被解析爲私有IP控制檯應用程序是解決公共

4

我的情況非常相似,但解決方案不同。在我的Windows 10開發機器+控制檯應用程序上,WebClient.UploadDatahttps地址工作得很好。但是,當相同的確切功能被複制到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; 

Source

相關問題