使用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
相关文档:
HTTP Error 500.19 - Internal Server Error
一 首先解锁
配置错误: 不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的(overrideModeDefault="Deny"),或者是通过包含 overrideMode="Deny" 或旧有的 allowOverride="false" 的位置标记明确设置的。
出现这个错误是因为 IIS 7.5 ......
在
vs2008为asp.net ajax添加js智能感知
今天找了好久,终于搞清楚了,scriptManager控件支持js智能感知,而从其继承的toolkitScriptManager不支持。至少在
vs2008b2中是这样。
要在js文件中添加asp.net ajax的js智能感知(与scriptManager控件无关),在js文件的开头添加这样一行即可:
//
/<referen ......
Online active users counter in ASP.NET
With this tool which is written for ASP.NET, it is possible to count the number of online users, members and guest users in web sites.
Installation
The tool installation is very simple and only takes a few minutes.
Step one - Add Reference:
After downlo ......
最近在看《asp.net通用模块及典型系统开发实例导航》,其中用到了MD5加密,代码如下: /// <summary>
/// 字符串加密函数
/// </summary>
/// <param name="strInput">输入被加密的字符串</param>
/// <returns>加密后的字符串</return ......