Webclient.DownloadFile()
방법으로 C# 콘솔 응용 프로그램에서 파일을 다운로드하려고합니다. A-ZA-z0-9라는 파일을 쉽게 다운로드 할 수 있습니다. 그러나 파일 이름에 '%'가 있으면 400 개의 잘못된 요청이 발생합니다.webclient에서 파일 이름을 '%'로 다운로드 할 수 없습니다 : 400 잘못된 요청 예외
string filename = "a%bc.txt";
string remotePath = "https://exampleURL.com/Folder/"+filename;
striing localPath = @"F:\"+filename;
using (WebClient client = new WebClient())
{
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
client.DownloadFile(new Uri(remotePath), localPath);
Console.WriteLine("Done");
}
나는 HTTPUtility.URLEncode()
을 시도했지만 그것은 404 오류를 준 : 아래
UPDATE : 다음은
예외 사항은 다음과 같습니다 %가 유효한 URL 문자이기 때문에
Exception information:
Exception type: HttpException
Exception message: A potentially dangerous Request.Path value was detected from the client (%).
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
(두 번째 코드 블록 등) HttpUtility''사용하여 코드를 기입하십시오 . 또한 ** 성공적으로 ** 파일을 다운로드하려면 웹 브라우저에서 사용한 URL을 확인하십시오. _Preferably 예를 들어 - ** 실제 ** url._ – mjwills
그 콘솔 애플 리케이션, 나는 웹 브라우저를 사용하지 마십시오. 또한, 미안 해요 실제 URL을 게시 할 수 없을 것입니다. – Parth