I need to "Post" some data to an external website using
HttpWebRequest
object from my application(desktop) and get a response
back into my application through HttpWebResponse
object.
But the webpage on which i m posting data have textboxes which have dynamic names.
How can I get the name of those textboxes and post data in HttpWebResquest
?
For example when I load the page the textbox name is like this U2FsdGVkX183MTQyNzE0MrhLOmUpqd3eL60xF19RmCwLlSiG5nC1H6wvtBDhjI3uM1krX_B8Fwc
but when I refresh the page name change to this U2FsdGVkX182MjMwNjIzMPAtotst_q9PP9TETomXB453Mq3M3ZY5HQt70ZeyxbRb118Y8GQbgP8
.
Thanks for any suggestions.
var request = WebRequest.Create("http://foo");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write("field=value");
}
You could et those names by XPath e.g. and user them like:
byte[] data = new ASCIIEncoding().GetBytes("textBoxName1=blabla");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/myservlet");
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = data.Length;
Stream myStream = httpWebRequest.GetRequestStream();
myStream.Write(data,0,data.Length);
myStream.Close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With