Send HTTP Post Request through ASP.net
20,597
it seems the url must be
string url = "http://revtr.cs.washington.edu/measure.php";
since is the action of the form.
Author by
asad
Updated on July 29, 2022Comments
-
asad almost 2 years
I've hit a road block due to this problem in my project, Any kind of help will be highly appreciated.
My problem is that I want users to enter (their) destination & email at my website. Then I'll take those values and fill in the text fields at the following website and then click the "request measurement button". In short a simple HTTP Post request.
http://revtr.cs.washington.edu/
My C# code is as follows:
// variables to store parameter values string url = "http://revtr.cs.washington.edu/"; // creates the post data for the POST request string postData = ("destination=www.thechive.com&node=161&email=abc%40xyz.edu.pk&prediction=If+you+believe+you+know+the+traceroute+%28for+instance%2C+if+you+are+trying+out+our+system+using+a+destination+that+you+actually+control%29%2C+please+cut-and-paste+the+traceroute+into+this+box+to+aid+us+in+improving+our+system."); // create the POST request HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = postData.Length; // POST the data using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream())) { requestWriter2.Write(postData); } // This actually does the request and gets the response back HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); string responseData = string.Empty; using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream())) { // dumps the HTML from the response into a string variable responseData = responseReader.ReadToEnd(); } // Now, find the index of some word on the page that would be // displayed if the login was successful int index = responseData.IndexOf("Measuring"); if (index > -1) ListBox1.Items.Add("SUCCESS");
But the responseData shows that the BUTTON hasn't been clicked when the program is run (I got this info from debugger of VS2010)