尝试使用特殊字符FTP文件
我有代码:
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url); request.Method = WebRequestMethods.Ftp.DownloadFile; request.UseBinary = true; // Binary mode when downloading request.Credentials = new NetworkCredential(user, password); FtpWebResponse response = (FtpWebResponse)request.GetResponse();
我总是得到错误:“请求的URI对此FTP命令无效”。
问题是url包含“#”。 由于我无法阻止人们创建该类型的文件,有没有办法可以转义特殊字符并仍然处理文件?
用"#" ->"%23"
替换字符串
URL编码不应包含哈希,因为:
由于各种原因,某些角色可能会在URL中被误解。 这些字符也应始终编码。
您可以使用HttpUtility.UrlEncode
对特殊字符进行编码。