How do I use MSXML2.ServerXMLHTTP to grab data from another site?

后端 未结 1 1630
陌清茗
陌清茗 2021-02-05 11:56

We have the folowing link: http://mvp.sos.state.ga.us/

Rather than create a db to replicate information that MVP page, we would like to use our own form, and then behind

1条回答
  •  囚心锁ツ
    2021-02-05 12:06

    You can use this component for http-requests like "POST", "GET", "DELETE" etc.

    To create the object:

    <%
        Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
    %>
    

    To send data using method "GET":

    <%
        objXML.Open "GET", "http://mvp.sos.state.ga.us/?some=querystring", false 
        objXML.Send ""
        Response.Write objXML.responseText
    %>
    

    Note that Open method has 3 parameters: HTTP method, URL, asynchronous call.

    Note that Send method on a "GET" ignores its parameter. (In this case we are passing parameters via the URL.)

    To send data using method "POST":

    <%
        objXML.Open "POST", "http://mvp.sos.state.ga.us/", false 
        objXML.Send "username=htbasaran&password=somepassword"
        Response.Write objXML.responseText
    %>
    

    Note for "POST" that Send method passes parameters in key-value pairs format like: key1=value1&key2=value2&so=on... or any other data like XML, JSON, etc.)

    These are the basics of this component. If you need more information, you can check microsoft's docs page out.

    An example code for getting form values and sending them using xmlhttp post method.

    <%
        ' getting form values
        my_uname = Request.Form("username")
        my_pword = Request.Form("password")
    
        ' creating object
        Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
    
        ' sending variables to an external site
        objXML.Open "POST", "http://www.sitename.com/login.asp", false
        objXML.Send "username=" & my_uname & "&password=" & my_pword
    
        ' Assuming that successful login will return response "Ok"
        ' writing the result to the client.
        if objXML.responseText="Ok" then
            Response.Write "Login Successful!"
        else
            Response.Write "Login Failed!"
        end if
    %>
    

    0 讨论(0)
提交回复
热议问题