当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 如何用asp+获取post的页面的数据

ASP.NET
在ASP.NET中自动给URL加上超级链接
在ASP.NET中怎么用Session判断用户是否登录?
C#是一种新的语言?或者仅仅只是Java
在网页中动态的生成一个图片
C#实现的18位身份证格式验证算法
Asp.net中的页面乱码的问题
ASP.NET中利用存储过程实现模糊查询
ASP.NET 2.0中构造个性化网页
.net教程:ASP.NET GridView的分页功能
ASP.Net中无刷新执行Session身份验证
用事实说话!AJAX应用程序开发七宗罪
迁移你的Web页面到ASP.NET AJAX 1.0
SQL Server 2005中插入XML数据方法
编程技巧 用Asp.net动态生成html页面
在asp.net 2.0 中使用的存储过程解析
用 asp.net 动态设置 WebService 引用
新手入门之ASP.NET2.0中的缓存技术解析
asp.net编程中实现 MD5 加密
ASP.NET备份恢复SqlServer数据库
Asp.Net输出数据到EXCEL表格中

ASP.NET 中的 如何用asp+获取post的页面的数据


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 141 ::
收藏到网摘: n/a

http://www.asp888.net 豆腐技术站

如何用asp+获取post的页面的数据
我们前面讲过如何跨站去抓取别的服务器页面上的数据[/title],但是那种方法只适合那些没有限制访问只能是
Post 的数据,比如我们下面的这个程序就是,我们举个最简单的例子:
test.htm
<form action="test.asp" method="post">
<input type=submit value="提交">
<input type=text name="txtName" value="豆腐制作,都是精品">
</form>
test.asp
<%
str1=request.FORM("txtName")
response.write str1
%>
这样,当我们以Get 的方法访问http://localhost/test.asp?txtName=doufu 的时候,我们得到的是空值
所以有的时候,我们必须模拟Post 的方法,我们知道在asp中aspHttp组件是可以实现这个功能的,我们现
在已经到了asp+的时代,所以,豆腐 我决定采用asp+来尝试一下,幸运的是,我成功了
下面我就把我的程序帖出来给大家看看
<%@ Assembly Name="System.Net" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language=vb runat=server>
Sub getPage(url As String, payload as String)

Dim req As WebRequest
Dim RequestStream As Stream
req = WebRequestFactory.Create(url)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim SomeBytes() as Byte
if payload <> Nothing

SomeBytes = System.Text.Encoding.default.GetBytes(payload)
req.ContentLength = SomeBytes.Length

RequestStream = req.GetRequestStream()
RequestStream.Write(SomeBytes, 0, SomeBytes.Length)
RequestStream.Close()
Else
req.ContentLength = 0
End if

Dim result As WebResponse
Dim ReceiveStream As Stream
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()
Dim read(512) As Byte
Dim bytes As Integer
bytes = ReceiveStream.Read(read, 0, 512)
Do while (bytes > 0)
Response.Write(System.Text.Encoding.default.GetString(read, 0, bytes))
bytes = ReceiveStream.Read(read, 0, 512)
Loop
End Sub

</script>
<%
getPage("http://gpsserver/study/test1.asp","txtName=豆腐制作,都是精品")
%>
我们看到,程序的输出就是我们的这个txtName的值,这就证明 我们的 模拟Post 的程序成功了!