2012-07-20 4 views
1

안녕하세요, 어떻게하면 프록시를 통해 HTML 페이지의 소스를 얻을 수 있습니까? 아래의 코드를 사용하면 "프록시 인증이 필요합니다."라는 오류 메시지가 나타납니다. 그리고 나는 대리인을 거쳐야 해. 이제 단지로 변환해야프록시를 통해 HTML 소스 가져 오기

Dim client As New WebClient() 

Dim htmlCode As String = client.DownloadString("http://www.stackoverflow.com") 

답변

3

그런 다음

더 많은 정보를 원하시면 http://msdn.microsoft.com/en-us/library/system.net.webclient.proxy.aspx

string source = GetPageSource("http://www.stackoverflow.com"); 

    private string GetPageSource(string url) 
    { 
     string htmlSource = string.Empty; 
     try 
     { 
      System.Net.WebProxy myProxy = new System.Net.WebProxy("Proxy IP", 8080); 
      using (System.Net.WebClient client = new System.Net.WebClient()) 
      { 
       client.Proxy = myProxy; 
       client.Proxy.Credentials = new System.Net.NetworkCredential("username", "password"); 
       htmlSource = client.DownloadString(url); 
      } 
     } 
     catch (WebException ex) 
     { 
      // log any exceptions 
     } 
     return htmlSource; 
    } 
+0

여기를 참조 인증이 필요하지 않습니다 프록시를 사용하지만 프록시 –

+0

을 통과해야 VB.Net하지만 쉽게 할 수 – JohnnBlade

+0

테스트 해 봤어? – JohnnBlade

관련 문제