使用WebClient自动填写并提交ASP.NET页面表单
使用WebClient自动填写并提交ASP.NET页面表单
在.NET中通过程序填写和提交表单还是比较简单。比如,要提交一个如下图所示的登录表单:
填写和提交以上表单的代码如下:
// 要提交表单的URI字符串。
string uriString = "http://www.xxx.com/Login.aspx";
// 要提交的字符串数据。
string postString = "userName=user1&password=password1";
// 初始化WebClient
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
// 将字符串转换成字节数组
byte[] postData = Encoding.ASCII.GetBytes(postString);
// 上传数据,返回页面的字节数组
byte[] responseData = webClient.UploadData(uriString, "POST", postData);
// 返回的将字节数组转换成字符串(HTML)
string srcString = Encoding.UTF8.GetString(responseData);
srcStrinig 就是提交表单后所返回页面的HTML。怎么样,很简单吧。
但是,以上代码可以提交ASP或JSP生成的表单,却不能提交ASP.NET表单。因为提交ASP.NET表单时,必须给“__VIEWSTATE”和“__EVENTVALIDATION”赋值。“__VIEWSTATE”和“__EVENTVALIDATION”的值可以通过在要提交的页面上按右键“查看源文件”中找到。如下:
id="__VIEWSTATE" value="/wEPDwUKM
相关文档:
最近公司需要开发一个简历导入功能,类似博客搬家或者邮箱搬家,之前抓取信息是利用火车采集器,但是简历导入功能需要用户登陆以后才能获取简历数据,无奈只好自己开发了。
首先是遇到的问题是:如何实现模拟登陆?
我们知道一般的网站都是通过Cookies来维护状态的,我抓的网站也是支持利用Cookies来验证用户的,构造一个 ......
我有一个login.aspx的页面,假如登录成功后就会自动跳转到index.html的框架.
index.html有三个页面,top.aspx,left.aspx,main.aspx,然后left.aspx里面显示用户信息
假如在left.aspx里没有Session的话,会返回login.aspx页面,而不显示index.html页面里的任何一页.
我现在的情况是没有Session的时候还是在i ......
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="图片滑动.aspx.cs" Inherits="ASP.net.图片滑动" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  ......
自从用了 ASP.Net MVC后就喜欢上了它 ,因为MVC对服务器控件的依赖大大减少,它生成的HTML页面就比WebForm清爽多了,加载速度有了明显的改善。
但对于页面中内嵌script,还是不能彻底的避免,如:
<script type="text/javascript" language="javascript">
//<!--
function DepositPa ......
Beyond File | New Company: from Cheesy Sample to Social Platform Scott Hanselman in Lagoon L on Monday at 11:30 AM The web has changed and there's a new way of thinking about your applications. You can't just write some HTML and CSS anymore and expect to be the next Twitter. Hear h ......