使用c#client将文件上传到https webserver

时间:2012-08-16 04:33:24

标签: c# ssl webserver

我想使用C#客户端从客户端计算机安全地上传文件到网络服务器。获得一些示例应用将会很有帮助。另外,我想知道如何使用ssl证书实现此目的。

谢谢,

阿都

1 个答案:

答案 0 :(得分:2)

 WebClient webClient = new WebClient();
        string webAddress = null;
        try
        {
            webAddress = @"http://myCompany/ShareDoc/";

            webClient.Credentials = CredentialCache.DefaultCredentials;

            WebRequest serverRequest = WebRequest.Create(webAddress);
            WebResponse serverResponse;
            serverResponse = serverRequest.GetResponse();
            serverResponse.Close();

            webClient.UploadFile(webAddress + logFileName, "PUT", logFileName);
            webClient.Dispose();
            webClient = null;
        }
        catch (Exception error)
        {
            MessageBox.Show(error.Message);
        }