首先,需要一個編碼設置的函數,因為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")
有需要的朋友可以拿去測試一下,如果有問題可以回復,大家一起討論。