You can take advantage of HttpWebRequest
, and set a string
for each textbox:
var response = SendNamedStrings("http://example.com", new Dictionary<string,string>{
{ "textBox1", textBox1.Text },
{ "textBox2", textBox2.Text },
{ "textBox3", textBox3.Text },
{ "textBox4", textBox4.Text }
} );
Where SendNamedStrings
could be something like
static WebResponse SendNamedStrings(string url, Dictionary<string, string> namedStrings)
{
string postData = "?" + string.Join("&", namedStrings.Select(pair => string.Format("{0}={1}", pair.Key, pair.Value)));
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
return request.GetResponse();
}
Note that this question has been asked in many ways before on stack overflow (here are just a few):
sending data using HttpWebRequest with a login page
How to add parameters into a WebRequest?
Sending POST data with C#