2009-02-07 110 views
0

這是我在客戶端和服務器端的代碼。我的代碼很簡單,只需將文件上傳到ASP.Net網站即可。文件上傳錯誤

我的客戶端代碼拋出異常,當它工作在Vista(64位,企業,SP1),但在Windows Server 2003

任何想法上正常工作?

10.10.12.162是我的服務器地址。

[代碼] 客戶:

static void Main(string[] args) 
    { 
     Console.Write("\nPlease enter the URI to post data to : "); 
     String uriString = Console.ReadLine(); 

     WebClient myWebClient = new WebClient(); 

     Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI"); 
     string fileName = Console.ReadLine(); 
     Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString); 

     DateTime begin = DateTime.Now; 

     byte[] responseArray = null; 
     try 
     { 
      responseArray = myWebClient.UploadFile(uriString, fileName); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.Message); 
      Console.WriteLine(ex.ToString()); 
     } 

     DateTime end = DateTime.Now; 

     Console.WriteLine("Elapsed time is: {0}", (end - begin).TotalMilliseconds); 
    } 

服務器:

public partial class FileUploadHandler : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     foreach (string f in Request.Files.AllKeys) 
     { 
      HttpPostedFile file = Request.Files[f]; 
      file.SaveAs("D:\\UploadFile\\UploadedFiles\\" + file.FileName); 
     } 
    } 
} 

從客戶端異常:

無法連接到遠程服務器 System.Net.WebException:無法連接到遠程服務器---> System.Net。 Sockets.SocketException:無連接可以作出,因爲目標機器 積極10.10.12.162:1031 在System.Net.Sockets.Socket.DoConnect(端點endPointSnapshot,SocketAddre SS的SocketAddress) 在System.Net.ServicePoint拒絕了.ConnectSocketInternal(布爾connectFailure,襪子等 S4,S6插座,插座&插座,ip地址&地址,ConnectSocketState狀態, IAsyncResult的asyncResult,的Int32超時,異常&例外) ---內部異常堆棧跟蹤結束--- 在System.Net.WebClient.UploadFile(Uri地址,字符串方法,String fileNam e) 在FileUploadClient.Program.Main(字串[] args)在d:\ UploadFile \ FileUploadClient \的Program.cs:行30 [/代碼]

問候, 喬治

回答

1

沒有什麼關於代碼會讓我太驚慌。

在機器上打開導致問題的遠程桌面。 打開命令行。 發出命令:

的telnet 10.10.12.162 1031

你看到一個光標,還是遠程登錄給你,它不能連接錯誤?如果你從telnet得到錯誤,你可能會遇到與你的代碼無關的NIC問題/防火牆問題/路由器問題/其他連接問題。

+0

Telnet失敗。但我嘗試ping主機是成功的。這是錯誤消息。有任何想法嗎?連接到10.10.12.162 ...無法打開連接到主機,在端口1031上:Connec t失​​敗 – George2 2009-02-08 09:10:37