ASP提交Post数据到远程网站的方法
分类:程序开发 Tags: asp 评论:0 浏览:11622 最近更新时间:2014/9/14 21:16:49
有时需要获取远程网站的某些信息,而服务器又限制了GET方式,只能通过POST数据提交,这个时候我们可以通过asp来实现模拟提交post数据。
首先,需要一个编码设置的函数,因为asp一般为gbk的,而标准的网站现在大都使用utf-8的。所以需要转码。
function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End function其次就是用组件实现post数据的提交了,我这里使用了MSXML2.SERVERXMLHTTP.3.0。当然也可以使用其他的。
function PostHTTPPage(url,data)
dim Http
set Http=server.createobject("MSXML2.SERVERXMLHTTP.3.0")
Http.open "POST",url,false
Http.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
Http.send(data)
if Http.readystate<>4 then
exit function
End if
PostHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
set http=nothing
if err.number<>0 then err.Clear
End function使用的时候就是这样:
PostHTTPPage("www.yuzhiguo.com","str1=a&str2=b&str3=c")本文地址:/546/
-
• centos系统挂载数据盘方法
• ASP提交Post数据到远程网站的方法
• Asp超精准判断客户端浏览器类型代码
• ASP Access数据库连接关闭与.ldb文件锁定解决方法
• JS显示当前年月日时间分秒代码(时间不断变动)
• 中国十大ASP CMS系统介绍
• ASP过滤所有超链接代码
• MySQL报Field‘***’doesn’t have a default value错误的解决办法
• UEditor百度编辑器在html代码模式无法更新内容的解决办法
• 打开网页自动弹出QQ对话框代码