【发布时间】:2013-01-31 12:31:58
【问题描述】:
我有以下接受文本文件的方法,我正在尝试将此文本文件上传到 Web 服务上。我使用用户名和密码。但我得到一个例外: “远程服务器返回错误:(404)未找到。”。如果我再次提供用户名和密码,我会得到同样的异常。我应该怎么做才能克服这个问题?
public static void UploadTextFileToWebService(string txtFile)
{
WebClient webClient = new WebClient();
string webAddress = null;
try
{
webAddress = @"https://www.myweb.org/mywebwebservices/dataupload.asmx";
webClient.Credentials = CredentialCache.DefaultCredentials;
WebRequest serverRequest = WebRequest.Create(webAddress);
WebResponse serverResponse;
serverResponse = serverRequest.GetResponse();
serverResponse.Close();
webClient.UploadFile(webAddress + txtFile, "PUT", txtFile);
webClient.Dispose();
webClient = null;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
【问题讨论】:
-
你能告诉我们网络服务吗?另外,不要使用
ex.Message作为诊断输出。使用ex.ToString()。
标签: c# .net asmx webclient webclient.uploaddata