這是我在客戶端和服務器端的代碼。我的代碼很簡單,只需將文件上傳到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 [/代碼]
問候, 喬治
Telnet失敗。但我嘗試ping主機是成功的。這是錯誤消息。有任何想法嗎?連接到10.10.12.162 ...無法打開連接到主機,在端口1031上:Connec t失敗 – George2 2009-02-08 09:10:37