Home>

Sometimes you need to get some information from a remote website,The server also limits the get method, which can only be submitted through post data.At this time, we can use asp to simulate submitting post data. There are many examples on the Internet.The following is a relatively simple and easy-to-understand function that I wrote myself.

First, we need a function for encoding settings,Because ASP is generally gbk, and most standard websites now use UTF-8. So conversion is needed.

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

The second is to implement the submission of post data using components.I used msxml2.serverxmlhttp.3.0 here. Of course, other ones can also be used.

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

This is how it works:

asp
  • Previous Implementation of SignalA using SignalR push service in Android
  • Next Linux binary universal package installation mysql5620 tutorial
  • Trends