如何用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 的程序成功了!