WebClient.DownloadFile下载文件,URL包含中文的问题

leavesosoon 2017-03-21 05:11:47
System.Net.WebClient webClient = new System.Net.WebClient();
webClient.DownloadFile("http://localhost:8080/downloadfile/中文测试.txt", "D\中文测试.txt");
我用这种方式进行下载文件,但是URL包含中文,解析不到地址,导致报错404.应该怎么搞?
...全文
382 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxiaol2 2017-10-20
  • 打赏
  • 举报
回复
System.Net.WebClient webClient = new System.Net.WebClient(); 这样 webClient.DownloadFile(Server.HtmlEncode("http://localhost:8080/downloadfile/中文测试.txt"), "D\中文测试.txt"); 或这样 webClient.DownloadFile(HttpUtility.HtmlEncode("http://localhost:8080/downloadfile/中文测试.txt"), "D\中文测试.txt");
Hvai 2017-10-20
  • 打赏
  • 举报
回复
我也遇到这问题,有搞定吗?
SoulRed 2017-03-21
  • 打赏
  • 举报
回复
encoder 一下。转码。

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧