■ HttpClient 클래스에서 HttpClientHandler 객체를 사용해 사용자 ID/패스워드를 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
using System.Net; using System.Net.Http; string userID = "admin"; string password = "1234"; NetworkCredential credential = new NetworkCredential(userID, password); using(HttpClientHandler handler = new HttpClientHandler { Credentials = credential }) { using(HttpClient client = new HttpClient(handler)) { // 작업을 처리한다. } } |