ASP simulated Post request method for asynchronous submission of data _ Application techniques

Source: Internet
Author: User

Sometimes need to get some information on the remote Web site, and the server has limited access, can only be submitted through post data, this time we can use ASP to implement the simulation of the post data, there are quite a number of such examples on the Internet. The following are the simpler and more straightforward functions I wrote myself.

First, you need a function of encoding settings, because the ASP is generally GBK, and standard sites are now mostly using Utf-8. So you need to convert.

Copy Code code as follows:

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 use the component to implement post data submission, I use the msxml2.serverxmlhttp.3.0 here. Of course, you can use the other.

Copy Code code as follows:

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 the way it is used:

Copy Code code as follows:

Posthttppage ("Www.jb51.net", "Str1=a&str2=b&str3=c")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.