我在http://10.1.10.211:8600/CardsPro+.exe有个文件
我试图用下面的代码检索它,但是得到了错误"HTTP 404.11 - Not “
private WebClient webClient;
private BackgroundWorker bgWorker;
private string tempFile;
private string md5;
internal string TempFilePath
{
get { return this.tempFile; }
}
internal UpdateInfoDownloadForm(Uri location, string md5, Icon programIcon)
{
InitializeComponent();
if (programIcon != null)
{
this.Icon = programIcon;
}
tempFile = Path.GetTempFileName();
this.md5 = md5;
webClient = new WebClient();
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
bgWorker = new BackgroundWorker();
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BgWorker_RunWorkerCompleted);
try
{
string strend = location.ToString().Substring(location.ToString().LastIndexOf('/')+1);
string strstart = location.ToString().Substring(0,location.ToString().LastIndexOf('/')+1);
strend = System.Web.HttpUtility.UrlEncode(strend);
Uri locn = new Uri(strstart+strend);
webClient.DownloadFileAsync(locn, this.tempFile); **//It fails here**
}
catch(Exception ex)
{ this.DialogResult = DialogResult.No; this.Close(); }
}如何传递Uri以获取文件中有特殊字符的文件?
当我更改文件名时,它起了作用。
发布于 2017-09-06 14:28:59
对于包含特殊字符的文件地址,要下载文件取决于服务器支持特殊字符访问的部署。
例如,如果IIS服务器不支持具有特殊字符的访问,那么您对url所做的更改是不可能的。
以下是处理包含特殊字符的文件名的解决方案,您可以参考它。
https://stackoverflow.com/questions/46046245
复制相似问题