C# WebClient FileDownLoad 에러 해결
using System;
using System.ComponentModel;
using System.Net;
namespace WebClient_FileDownLoad
{
class ClientDownLoadFile
{
static void Main( string[] args )
{
// 서버측에서 알 수 없는 헤더 Agent로 인해서 정상적인 파일다운 불가
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler( FileDownLoadCompleted );
// 익스플로러의 헤더 에이전트 추가해서 문제 해결
webClient.Headers.Add( "User-Agent",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.3; WOW64; Trident/7.0)" );
string sUrl = "파일 다운로드 주소";
webClient.DownloadFileAsync( new Uri( sUrl ), "다운파일 이름" );
Console.ReadLine();
}
static void FileDownLoadCompleted( object sender, AsyncCompletedEventArgs e )
{
Console.WriteLine( "DownLoad Finished...." );
}
}
}
'C#' 카테고리의 다른 글
비주얼 스튜디오 설치후 추가 확장 애드인 (0) | 2015.05.20 |
---|---|
HighLight.JS 티스토리에서 사용 하기. (0) | 2014.07.06 |
티스토리에서 브라우저 API Key 구글 ShortURL 호출 (0) | 2014.07.05 |
C# 구글 ShortURL (0) | 2014.06.24 |
테스트 스크립트 (0) | 2014.06.23 |