4

I want to get the data from this page and insert it to my mssql database. How can I read this data with asp.net c#? SehisID is a value from 1 to 81.

EDIT: My code is below.

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>"; } 
2
  • 3
    Well, you tagged it with the answer. System.Net.HttpWebRequest and read the response. Commented Jul 28, 2010 at 15:47
  • Didn't know that :D. But still need a simple how to example.. Commented Jul 28, 2010 at 15:49

2 Answers 2

10

WebClient is an easy way to get a string from a web page:

WebClient client = new WebClient(); String downloadedString = client.DownloadString("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=81"); 
Sign up to request clarification or add additional context in comments.

1 Comment

Personal note: client.Encoding = System.Text.Encoding.UTF8;
1

And next code works well too:

 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>"; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.