WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential("id", "pass");
이렇게 하면 됩니다.
byte[] contents = Encoding.ASCII.GetBytes("id:pass");
string authText = Convert.ToBase64String(contents);
string authHeader = "Basic " + authText;
WebClient wc = new WebClient();
wc.Headers.Add("Authorization", authHeader);
이렇게 하면 됩니다.
그런데 위 소스를 WebBrowser 에 적용 시키면
webBrowser1.Navigate("http://주소", string.Empty, null, authHeader);
안되더라구요. 그래서 구글에서 찾은 코드로
webBrowser1.Navigate("http://id:pass@주소");
했더니 됩니다. 궁굼한것은..
byte[] contents = Encoding.ASCII.GetBytes("id:pass");
string authText = Convert.ToBase64String(contents);
string authHeader = "Basic " + authText;
webBrowser1.Navigate("http://주소", string.Empty, null, authHeader);
위 코드는 안되고
webBrowser1.Navigate("http://id:pass@주소");
이 코드는 되는 이유는 뭘까 하는 부분입니다.
[최초 등록일: ]
[최종 수정일: 7/8/2014]