为了实现自动提交表单,我在本地做了两个简单页面1.asp和2.asp
1.asp代码如下:
<html>
<head>
</head>
<body>
<form action="2.asp" method="post" >
<input type="text" id="userName" name="userName"/>
<input type="text" id="password" name="password"/>
<input type="submit" />
</form>
</body>
</html>
2.asp代码如下:
<%
username=request.Form("username")
password=request.Form("password")
response.write "用户名和密码是"&username&password
%>
然后我写了个C# 小程序。
// 要提交表单的URI字符串。
string uriString = "http://localhost/1.asp";
// 要提交的字符串数据。
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);可是为什么srcString 不是我预想中的接受提交信息的2.asp页面的内容“用户名和密码是user1password1”,而是1.asp的内容<html>
<head>
</head>
<body>
<form action="2.asp" method="post" >
<input type="text" id="userName" name="userName"/>
<input type="text" id="password" name="password"/>
<input type="submit" />
</form>
</body>
</html>
这是为什么呢?
1.asp代码如下:
<html>
<head>
</head>
<body>
<form action="2.asp" method="post" >
<input type="text" id="userName" name="userName"/>
<input type="text" id="password" name="password"/>
<input type="submit" />
</form>
</body>
</html>
2.asp代码如下:
<%
username=request.Form("username")
password=request.Form("password")
response.write "用户名和密码是"&username&password
%>
然后我写了个C# 小程序。
// 要提交表单的URI字符串。
string uriString = "http://localhost/1.asp";
// 要提交的字符串数据。
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);可是为什么srcString 不是我预想中的接受提交信息的2.asp页面的内容“用户名和密码是user1password1”,而是1.asp的内容<html>
<head>
</head>
<body>
<form action="2.asp" method="post" >
<input type="text" id="userName" name="userName"/>
<input type="text" id="password" name="password"/>
<input type="submit" />
</form>
</body>
</html>
这是为什么呢?
解决方案 »
- 未将对象引用设置到对象的实例
- LoginStatus 如何指向不同的登陆地址
- 奇怪?在Application_BeginRequest()进行地址重写,发布网站后却不管用!
- Jmail发邮件的时候 The message was undeliverable
- 开发一个类似于51JOB这样的网站,一个6个人的团,需要多久?
- 请教ASP.NET缓存的使用
- 地址栏如何显示iframe src的路径
- 急救:关于ASP.NET2.0登陆控件登陆出错问题
- 怎样在 .vb 文件中去控制某个文本框得到焦点?
- 请问aspx,aspx.vb,aspx.cs应该如何分离代码?
- |zyciis| 现在客户要求网站要有三种语言,简,繁,英, 以下是我的设计,大家看可不可以
- <add key="kedb" value="server=bjxxd-dqsrw5l1o;uid=bjxxd_2008_SiteWeb;pwd=bjxxd_2
“应该往2.asp里面POST
string uriString = "http://localhost/2.asp"; ”那么就会出现这样的问题srcString="用户名和密码是"
而不是预想中的srcString="用户名和密码是user1password1"
也就是说
username=request.Form("username")
password=request.Form("password")
这些是没有获取到值的,整个表单提交也没有失败了。