Unable to POST using HTTPWebRequest
Hello All
I have given below the code snippet of the HttpWebRequest that I am sending to the login page. The login.asp is the login page but it is ALSO the page where the login validation occurs.
Now my problem is that using C# I am unable to login and go to the next page but I am able to do this using XMLHTTP in ASP.
The application remains at the same page and retrieves the HTML of that page only.
For now I have only included the request part of my code.
Any help is greatly appreciated. I did try using the code posted in a very old post in this forum but even that did not work.
Regards
Satish
CODE
ASCIIEncoding encoding = new ASCIIEncoding();
string strPost = "submit=Login&userid=abc&passwd=abcd";
byte[] data = encoding.GetBytes(strPost);
HttpWebRequest myHttpWebRequest1 =
(HttpWebRequest)WebRequest.Create("http://localhost/login.asp");
myHttpWebRequest1.Method = "POST";
myHttpWebRequest1.ContentType =
"application/x-www-form-urlencoded";
myHttpWebRequest1.ContentLength = data.Length;
Stream newStream = myHttpWebRequest1.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();