这是我在客户端和服务器端的代码。我的代码很简单,只需将文件上传到 ASP.Net 网站。
我的客户端代码在 Vista(x64、Enterprise、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:无法建立连接,因为目标计算机在 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure) 的 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre ss socketAddress) 处主动拒绝了它, Sock et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)---内部异常堆栈跟踪结束---在 System.Net.WebClient.UploadFile(Uri address, String 方法,String fileName e) at FileUploadClient.Program.Main(String[] args) in D:\UploadFile\FileUploadClient\Program.cs:line 30 [/Code]
问候,乔治