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:
Related articles
- Python imitates POST to submit HTTP data and uses cookie values
- PHP uses ajax data to submit posts and post common methods summary
- Ci detection method for ajax or page post data submission
- Python method of submitting data through post
- Method to solve the problem that angular $httppost () cannot receive parameter values when submitting data in the background
- Method for submitting data to Tomcat server using Get method
- Method for submitting data to Tomcat server using Post method
Trends