你如何编程的形式和“POST”网页填写? [英] How do you programmatically fill in a form and 'POST' a web page?

查看:169
本文介绍了你如何编程的形式和“POST”网页填写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#和ASP.NET我想在一个网页(形式),然后POST这些价值观的一些值(4文本框)编程填写。我该怎么做呢?

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?

编辑:澄清:有,你可以将他们的添加页面上提交的IP,用户名和电子邮件地址服务(www.stopforumspam.com)。我希望能够无需进行复制/粘贴它们跨越并点击提交按钮创建我的网站的页面上的链接/按钮,将在这些值填写并提交信息。

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.

进一步澄清:如何做自动化的垃圾邮件机器人的填写表格,然后点击提交按钮,如果他们写在C#

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

推荐答案

您可以看到,这里一个示例:的http:// en.csharp-online.net/HTTP_Post

You can see a sample of that here: http://en.csharp-online.net/HTTP_Post

基本上,code会是这个样子:

Basically, the code will look something like this:

WebRequest req = WebRequest.Create("http://mysite/myform.aspx");
string postData = "item1=11111&item2=22222&Item3=33333";

byte[] send = Encoding.Default.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = send.Length;

Stream sout = req.GetRequestStream();
sout.Write(send, 0, send.Length);
sout.Flush();
sout.Close();

WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string returnvalue = sr.ReadToEnd();

这篇关于你如何编程的形式和“POST”网页填写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆