Navigating a web form
-
I'm trying to fill in a text box then hit the submit button using httpwebrequest. Here is a sample using googles home page(just because everyone can use it). I just cant seem to get it to work. Thanks for the help. string Uri = "http://www.google.com"; string requestString = "q=test&btnG=Clicked"; byte[] requestData = Encoding.UTF8.GetBytes(requestString); HttpWebRequest request = null; Stream stream = null; HttpWebResponse response = null; // set up request CookieContainer _cookies = new CookieContainer(); request = (HttpWebRequest)WebRequest.Create(Uri); request.Proxy = null; request.CookieContainer = _cookies; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = requestData.Length; // make form post stream = request.GetRequestStream(); stream.Write(requestData, 0, requestData.Length); // get response response = (HttpWebResponse)request.GetResponse();
-
I'm trying to fill in a text box then hit the submit button using httpwebrequest. Here is a sample using googles home page(just because everyone can use it). I just cant seem to get it to work. Thanks for the help. string Uri = "http://www.google.com"; string requestString = "q=test&btnG=Clicked"; byte[] requestData = Encoding.UTF8.GetBytes(requestString); HttpWebRequest request = null; Stream stream = null; HttpWebResponse response = null; // set up request CookieContainer _cookies = new CookieContainer(); request = (HttpWebRequest)WebRequest.Create(Uri); request.Proxy = null; request.CookieContainer = _cookies; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = requestData.Length; // make form post stream = request.GetRequestStream(); stream.Write(requestData, 0, requestData.Length); // get response response = (HttpWebResponse)request.GetResponse();
Where exactly do you get the error?
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates