<p>Using C# and ASP.NET I want to programmatically fill in some values (4 text boxes) on a web page (form) and then 'POST' those values. How do I do this?</p>

<p>Edit: Clarification: There is a service (www.stopforumspam.com) where you can submit ip, username and email address on their 'add' page. I want to be able to create a link/button on my site's page that will fill in those values and submit the info without having to copy/paste them across and click the submit button.</p>

<p>Further clarification: How do automated spam bots fill out forms and click the submit button if they were written in C#?</p>

[{'answer_id': 26881, 'author': 'Ryan Farley', 'author_id': 1627, 'author_profile': 'https://Stackoverflow.com/users/1627', 'pm_score': 7, 'selected': True, 'text': '<p>The code will look something like this:  </p>\n\n<pre><code>WebRequest req = WebRequest.Create("http://mysite/myform.aspx");\nstring postData = "item1=11111&amp;item2=22222&amp;Item3=33333";\n\nbyte[] send = Encoding.Default.GetBytes(postData);\nreq.Method = "POST";\nreq.ContentType = "application/x-www-form-urlencoded";\nreq.ContentLength = send.Length;\n\nStream sout = req.GetRequestStream();\nsout.Write(send, 0, send.Length);\nsout.Flush();\nsout.Close();\n\nWebResponse res = req.GetResponse();\nStreamReader sr = new StreamReader(res.GetResponseStream());\nstring returnvalue = sr.ReadToEnd();\n</code></pre>\n'}, {'answer_id': 26932, 'author': 'Ryan Rinaldi', 'author_id': 2278, 'author_profile': 'https://Stackoverflow.com/users/2278', 'pm_score': 1, 'selected': False, 'text': '<p>View the source of the page and use the WebRequest class to do the posting.  No need to drive IE.  Just figure out what IE is sending to the server and replicate that.  Using a tool like Fiddler will make it even easier.</p>\n'}, {'answer_id': 8378787, 'author': 'John Kelvie', 'author_id': 929047, 'author_profile': 'https://Stackoverflow.com/users/929047', 'pm_score': 2, 'selected': False, 'text': '<p>You can use the UploadValues method on WebClient - all it requires is passing a URL and a NameValueCollection. It is the easiest approach that I have found, and the MS documentation has a nice example:<br>\n<a href="http://msdn.microsoft.com/en-us/library/9w7b4fz7.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/9w7b4fz7.aspx</a></p>\n\n<p>Here is a simple version with some error handling:    </p>\n\n<pre><code>var webClient = new WebClient();\nDebug.Info("PostingForm: " + url);\ntry\n{\n     byte [] responseArray = webClient.UploadValues(url, nameValueCollection);\n     return new Response(responseArray, (int) HttpStatusCode.OK);\n}\ncatch (WebException e)\n{\n     var response = (HttpWebResponse)e.Response;\n     byte[] responseBytes = IOUtil.StreamToBytes(response.GetResponseStream());\n     return new Response(responseBytes, (int) response.StatusCode);\n}  \n</code></pre>\n\n<p>The Response class is a simple wrapper for the response body and status code.   </p>\n'}, {'answer_id': 14978752, 'author': 'John', 'author_id': 1252113, 'author_profile': 'https://Stackoverflow.com/users/1252113', 'pm_score': 0, 'selected': False, 'text': '<p>I had a situation where I needed to post free text from a html textarea programmatically and I had issues where I was getting <code>&lt;br /&gt;</code> in my param list i was building.</p>\n\n<p>My solution was a replace of the br tags with linebreak characters and htmlencoding just to be safe.</p>\n\n<pre><code>Regex.Replace( HttpUtility.HtmlDecode( test ), "(&lt;br.*?&gt;)", "\\r\\n" ,RegexOptions.IgnoreCase);\n</code></pre>\n'}, {'answer_id': 30785403, 'author': 'user3887407', 'author_id': 3887407, 'author_profile': 'https://Stackoverflow.com/users/3887407', 'pm_score': 0, 'selected': False, 'text': '<p>Where you encode the string:</p>\n\n<blockquote>\n  <p>Encoding.Default.GetBytes(postData);</p>\n</blockquote>\n\n<p>Use Ascii instead for the google apis:</p>\n\n<blockquote>\n  <p>Encoding.ASCII.GetBytes(postData);</p>\n</blockquote>\n\n<p>this makes your request the same as and equivalent "curl --data "..." [url]" request</p>\n'}, {'answer_id': 40257908, 'author': 'Sadid Khan', 'author_id': 1999720, 'author_profile': 'https://Stackoverflow.com/users/1999720', 'pm_score': 0, 'selected': False, 'text': '<p>you can send a post/get request with many ways. Different types of library is there to help. \nI found it is <strong>confusing</strong> to choose which one I should use and what are the <strong>differences</strong> among them. </p>\n\n<p>After surfing stack overflow this is the <strong>best answer I found</strong>. this thread explains all</p>\n\n<p><a href="https://stackoverflow.com/a/4015346/1999720">https://stackoverflow.com/a/4015346/1999720</a></p>\n'}]
['https://Stackoverflow.com/questions/26857', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1463/']