Extract data from url in ASP.NET

I am new to asp.net,

ı want to get data from url to asp.net. and we need data to store in a string.

if this is my url i want to get this url 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

      

+3


source to share


2 answers


try it



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);

      

+5


source


WebClient

useful for this kind of thing (scartag's answer demonstrates the simplicity of this), but for more advanced options, you should look in the base class WebRequest

:



// 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 ();

      

+2


source







All Articles