Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate a visit to a url?

Tags:

c#

asp.net

I have a page where a user submits an order, and after they submit it, I want to hit a url (http://externalsite.com?id=12345&sessionid=abc123) without actually redirecting them to the external page.

Is there a way to do this?

like image 760
Steven Avatar asked Jun 20 '12 20:06

Steven


Video Answer


1 Answers

Sure, use an HttpWebRequest from your server-side code. Here's an example:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
    "http://externalsite.com?id=12345&sessionid=abc123");
request.Method = "GET";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    string result = reader.ReadToEnd();
    // Process the response text if you need to...
}
like image 174
voithos Avatar answered Sep 21 '22 19:09

voithos