2010-07-28 15 views
3

this 페이지에서 데이터를 가져와 내 mssql 데이터베이스에 삽입하고 싶습니다. asp.net C#으로 어떻게이 데이터를 읽을 수 있습니까? SehisID는 1에서 81 사이의 값입니다.웹 페이지에서 데이터를 가져 오는 방법은 무엇입니까?

편집 : 내 코드는 다음과 같습니다.

for (int i = 1; i <= 81; i++) 
{ 
    HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=" + i); 
    rqst.Method = "POST"; 
    rqst.ContentType = "text/xml"; 
    rqst.ContentLength = 0; 
    rqst.Timeout = 3000; 

    HttpWebResponse rspns = (HttpWebResponse)rqst.GetResponse(); 
    form1.InnerHtml += rspns.ToString() + "<br>"; 
} 
+3

글쎄, 당신은 대답을 태그. System.Net.HttpWebRequest'를 읽고 응답을 읽습니다. – dotjoe

+0

몰랐 : D. 하지만 여전히 간단한 예제가 필요합니다 .. –

답변

9

WebClient는 웹 페이지에서 문자열을 얻을 수있는 가장 쉬운 방법입니다 :

WebClient client = new WebClient(); 
String downloadedString = client.DownloadString("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=81"); 
+2

개인 메모 : client.Encoding = System.Text.Encoding.UTF8; –

1

을 그리고 다음 코드가 너무 잘 작동합니다

 for (int i = 1; i <= 81; i++) 
     { 
      var rqst = (HttpWebRequest)WebRequest.Create("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=" + i); 
      rqst.Method = "POST"; 
      rqst.ContentType = "text/xml"; 
      rqst.ContentLength = 0; 
      rqst.Timeout = 3000; 

      var rspns = (HttpWebResponse)rqst.GetResponse(); 
      var reader = new StreamReader(rspns.GetResponseStream()); 
      form1.InnerHtml += reader.ReadToEnd() + "<br>"; 
     } 
관련 문제