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

ASP.NET
灵活正确的实现.NET插件机制
在Asp.net中为图像加入版权信息
重构Session确实让代码简洁干净了不少
JSP与ASP.Net之间的Session值共享
如何获取当前程序文件的路径 Current Path
在.NET框架应用程序中发送电子邮件
asp.net开发wap程序必备:识别来访手机品牌型号
ASP.NET 2.0中使用自定义provider
asp.net开发wap必备:更好的匹配手机设备
用ashx动态生成文件
ASP.NET中17种正则表达式
提高ASP.Net应用程序性能的十大方法
一个通过web.Mail发送邮件的类
在DataGrid里面根据日期的不同显示new图标
Asp.Net细节性问题精萃
自定义控件中使用枚举类型的属性(原创)
.NET开发 正则表达式中的 Bug
.Net学习:IronPython分析Lambda表达式
ASP.NET中的Response对象的方法
在ASP.NET 2.0中数据绑定的实现方法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 148 ::
收藏到网摘: 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 的程序成功了!