如何以编程方式调用示例网页上的按钮

时间:2012-05-15 10:11:03

标签: c# .net httpwebrequest http-post

我确实尝试过类似网页上的内容。我的意思是,在网页上我点击按钮,post事件从asp页面请求我的查询结果。

我在这里以编程方式尝试;

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

2 个答案:

答案 0 :(得分:1)

考虑使用http://watin.org/

答案 1 :(得分:0)

参数不合适,这就是我使用firebug查看帖子数据的原因。然后它正在运作。