易截截图软件、单文件、免安装、纯绿色、仅160KB

使用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


相关文档:

Asp.net图片滚动


<%@ 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" />
    ......

PHP与ASP.NET比较的浅析 南三方


 
PHP与ASP.NET比较的各个方面是什么呢?PHP与ASP.NET比较的必要性是什么呢?那么本文就给你一个答案。
PHP与ASP.NET比较的前言,不管你是不是已经选择了PHP,根据它在如下表格中在价格、速度、效率、安全性、平台支持性和开源与否上的表现,我们都能判断出它的强项是远胜于弱点的。唯一不足的是缺少面向对象的支 ......

asp.net 中 request 与 context.request有什么区别?

Request 属性提供对 HttpRequest 类的属性和方法的编程访问。由于 ASP.NET 页包含对 System.Web 命名空间(含有 HttpContext 类)的默认引用,因此在 .aspx 页上可以引用 HttpContext 的成员,而不需要对 HttpContext 的完全限定类引用。例如,可只使用 Request.Browser 获取客户端浏览器的功能。但是,如果要从 ASP.NET 代 ......

Mix 10 上的asp.net mvc 2的相关Session

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 ......

Online active users counter in ASP.NET


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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号