fetch data from URL in ASP.NET

Go To StackoverFlow.com

3

i am new to asp.net,

ı want to get data from url on asp.net. & need data to be in store into string.

if suppose this is my URL thn i want to fetch this URL Data in string,

http://www.islamicfinder.org/prayer_service.php?country=bahrain&city=manama&state=02&zipcode=&latitude=26.2361&longitude=50.5831&timezone=3.00&HanfiShafi=1&pmethod=4&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml
2012-04-04 08:18
by Krunal


5

Try this

string url = "http://www.islamicfinder.org/prayer_service.php?country=bahrain&city=manama&state=02&zipcode=&latitude=26.2361&longitude=50.5831&timezone=3.00&HanfiShafi=1&pmethod=4&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml";
            var webClient = new WebClient();
            string data = webClient.DownloadString(url);
2012-04-04 08:22
by scartag
i want to store this data into my table, how should i, do this - Krunal 2012-04-04 08:28
Create this table and store use Entity Framework for i - Arbejdsglæde 2012-04-04 08:30
@krunal It depends on a lot of things. What database are you using? what data access technology - scartag 2012-04-04 08:30
i am not using any db, i just want to store this data in my HTML TABLE.. how should i, do this - Krunal 2012-04-04 08:49
@krunal you'll need to provide more info on how you want the table formated. is the table already on the page? pls edit your question to enable me answer accurately or create a new question and paste the link here - scartag 2012-04-04 09:05
i want to fetch data from this url "http://ipad.idealake.com/default.aspx?id=G" and i want to display this data in my HTML Table.. i tried this ("http://geekswithblogs.net/dotNETvinz/archive/2009/06/24/fill-asp.net-table-with-data-from-datatable.aspx") code but it shows me error in form1 - Krunal 2012-04-04 10:06
for eg: my 1st row is " DRREDDY 1712.55 1693.05 1.15 " 2nd row: MARUTI 1315.70 1309.55 0.47 ... and so on - Krunal 2012-04-04 10:08
@krunal create a new question, post your code and explain what issues you are having and then come back here to post the stackoverflow link to your question. i'll be able to help if u do that. we can't solve it via comment - scartag 2012-04-04 10:16


2

WebClient is useful for this kind of thing (scartag's answer demonstrates the simplicity of this), but for more advanced options you should look at the underlying WebRequest class:

// Create a request for the URL.        
WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");

// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;

// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

// Display the status.
Console.WriteLine (response.StatusDescription);

// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();

// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);

// Read the content.
string responseFromServer = reader.ReadToEnd ();

// Display the content.
Console.WriteLine (responseFromServer);

// Cleanup the streams and the response.
reader.Close ();
dataStream.Close ();
response.Close ();
2012-04-04 08:23
by mdm
Ads