2009-02-07 109 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