使用WebClient自动填写并提交ASP.NET页面表单的源代码
try
{
// 要提交表单的URI字符串。
string uriString = "http://localhost:1165/WebTest/MyLogin.aspx";
///////////////////////////////////////
// 打开页面
///////////////////////////////////////
WebClient webClient = new WebClient();
byte[] responseData = webClient.DownloadData(uriString);
string srcString = Encoding.UTF8.GetString(responseData);
///////////////////////////////////////
// 填写页面并提交
///////////////////////////////////////
webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
// 获取页面的 VeiwState
string viewStateFlag = "id=\"__VIEWSTATE\" value=\"";
int i = srcString.IndexOf(viewStateFlag) + viewStateFlag.Length;
int j = srcString.IndexOf("\"",i);
string viewState = srcString.Substring(i, j-i);
&nb
相关文档:
1.设置web.config文件.
<system.web>
......
<globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312" />
......
</system.web>
或者:
aspx文件中:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"&g ......
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 ......
在
vs2008为asp.net ajax添加js智能感知
今天找了好久,终于搞清楚了,scriptManager控件支持js智能感知,而从其继承的toolkitScriptManager不支持。至少在
vs2008b2中是这样。
要在js文件中添加asp.net ajax的js智能感知(与scriptManager控件无关),在js文件的开头添加这样一行即可:
//
/<referen ......
asp.net中自带的CutString只能截取字符数量的长度,但中英文字符数有差异,一个中文字等同于二个英文字符的宽度,这样对截取后的效果不理想.使用以下的方法就能解决.
//调用方法
string title=BLL.CutStr.CutString("标题",10);using System;
using System.Collections.Generic;
using System.Text;
namespace BLL
{
&n ......
最近在看《asp.net通用模块及典型系统开发实例导航》,其中用到了MD5加密,代码如下: /// <summary>
/// 字符串加密函数
/// </summary>
/// <param name="strInput">输入被加密的字符串</param>
/// <returns>加密后的字符串</return ......