Search code examples
c#.nethttpwebrequesthttp-post

How can I invoke a button on an example web page programmatically


I did try something like I do on the web page. I mean , on the web page I click the button and the post event requests my query result from an asp page.

Here I do try it programmatically;

string paramaters = "sql=select+%2A+from+hsp%5Fistanbul+u+where+u%2Ehsp%5Fhosdere%5Fno+%3D+28960099";
    string strResponse;

HttpWebRequest requestLogin = (HttpWebRequest)WebRequest.Create("http://10.1.20.39/query/query.asp");
requestLogin.Credentials = new NetworkCredential("xyz", "tyewrrf"); 
requestLogin.Method = "POST"; 
 requestLogin.ContentType = "application/x-www-form-urlencoded"; 
requestLogin.ContentLength = paramaters.Length; 
StreamWriter stOut = new StreamWriter(requestLogin.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(paramaters); 
stOut.Close();
HttpWebResponse responseLogin = (HttpWebResponse)requestLogin.GetResponse(); 
StreamReader stIn = new StreamReader(responseLogin.GetResponseStream());
strResponse = stIn.ReadToEnd();// here I want to get the the same html codes as if I do click on the web page...
stIn.Close();  

Solution

  • paramaters was not okay, that is why I used firebug to see the post data. And then it was working.