我如何远程发送数据并填写不同的网络表单? [英] how do i remotely send data and fill up different webforms?

查看:140
本文介绍了我如何远程发送数据并填写不同的网络表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个可以填充其他网页并给我结果页面的程序?比如提交电子邮件帐户表单并接收结果表格并保存文本/页面。使用c#/ asp.net?

解决方案

你不需要填满任何东西。 (它可能是什么?:-))



让我们看看。当您充当浏览器的用户并填写Web表单的控件,然后单击提交时,浏览器将使用您输入的数据创建HTTP请求并将其发送到服务器。此请求包含您使用键值对输入的参数;该键与表单下每个输入控件的属性 name 相同,值为其字符串值。



所以,你需要它在没有浏览器的情况下做同样的事情。您应该知道每个表单的HTTP请求的结构是什么,并发送相同的请求,获取HTTP响应,然后内容是此响应将是您正在寻找的结果页面的内容。 br />


要这样做,你需要使用类 System.Net.HttpWebRequest

http://msdn.microsoft.com/en-us/library/system。 net.httpwebrequest.aspx [ ^ ]。



以下是获得HTTP响应的方式: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx [ ^ ]。



请参阅我过去的答案:

从网页获取特定数据 [ ^ ],

如何从其他网站获取数据 [ ^ ]。



现在,要了解表单的HTTP请求的结构?显然,通过查看您想要模仿的表单的HTML源代码,这可以通过浏览器的查看源代码菜单项(或类似的东西)轻松完成。注意上面提到的控件'名称属性。



键值对的格式显示在不少地方。例如,请参阅代码示例(请参阅第一个答案): http://stackoverflow.com/questions/10263082/how-to-pass-post-parameters-to-asp-net-web-request [ ^ ]。



在编写自己的小型ASP.NET应用程序(可以使用Visual Studio中包含的调试HTTP服务器在本地主机上调试)时调试技术会很好,看看如何表单及其数据被转换为HTTP请求,您可以在服务器端进行测试。对于你的工作代码,这不是必需的,我的意思是只是学习阶段,这可以节省你相当长的时间。



-SA

how do i make a program which can fill up other webpages and give me the result page?. like submitting a email account form and receiving the result form and save the text/page. using c#/asp.net?

解决方案

You don't need to "fill up" anything. (What it could be? :-))

Let's see. When you act as a user of a browser and fill up controls of a Web form, and then click "submit", the browser uses the data you input to create an HTTP request and sends it to the server. This request carries the parameters you input using key-value pairs; the key is the same as the attribute name of each input control under the form and the value is its string value.

So, all you need it to do the same thing without a browser. You should know what is the structure of the HTTP request in case of each form and send the same very request, obtain the HTTP response and then the content is this response will be the content of the "result page" you are looking for.

To do so, you need to use the class System.Net.HttpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

Here is how you get the HTTP response: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx[^].

Please see also my past answers:
get specific data from web page[^],
How to get the data from another site[^].

Now, to learn the structure of the HTTP request for the form? Apparently, by looking at the HTML source code for the forms you want to mimic, which is easily done through browser's "View Source Code" menu item (or something like that). Pay attention for controls' name attributes mentioned above.

The format of the key-value pairs is shown in many places. For example, see code sample (please see the first answer): http://stackoverflow.com/questions/10263082/how-to-pass-post-parameters-to-asp-net-web-request[^].

It would be good the debug the technique when be writing your own small ASP.NET application (which you can debug on local host using the debug HTTP server included in Visual Studio), to see how the form and its data is translated into an HTTP request, which you can test on the server side. For your working code this is not needed, I mean just the study stage, which can save you considerable time.

—SA


这篇关于我如何远程发送数据并填写不同的网络表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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