We can use WebRequest and WebResponse classes in ASP.NET and C# to call a URL and read its content.
Step 1. Import the following namespaces in your application.
- using System.Net;
- using System.IO;
Step 2. Copy and paste given function in your .cs file.
- public void callurl(string url)
- {
- WebRequest request = HttpWebRequest.Create(url);
- WebResponse response = request.GetResponse();
- StreamReader reader = new StreamReader(response.GetResponseStream());
- string urlText = reader.ReadToEnd(); // it takes the response from your url. now you can use as your need
- Response.Write(urlText.ToString());
- }
In the above code, a WebRequest object is created by passing a URL. The GetResponse returns a WebResponse object and that is the stream with the content of a web page. After that, the content is read in a string.
Step 3. Call this function on a button click or anywhere you need it.
- callurl("http://google.com");
Learn more here, Using WebRequest and WebResponse In ASP.NET and C#


Jagadish VadavattiPosted Sep 22, 2019, 2:27 AM EDT
Hi Pankaj,,, I am facing a issue with same kind of, please help me to come out of this... I have URL ("abcd.com?login=true"). Now I have to pass the Username, Password and PIN to this URL as part of authentication and after that it will redirect to another URL ("abcd.come?token=asjfH1234").... Here I want to get the "asjfH1234" token query string or full URL inside my code.. Please help on this some set of Code.
DeepanPosted Sep 18, 2019, 11:11 PM EDT
Good article
MeikandanathanPosted Aug 15, 2019, 10:04 PM EDT
Var client = new WebClient();var content = client.DownloadString("http://google.com");
MeikandanathanPosted Aug 15, 2019, 10:02 PM EDT
We can also easily to do this, by using WebClient class