19

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 the scenes, send information to the site above to get results back using component called MSXML2.ServerXMLHTTP.

Unfortunately, I know nothing about this component or how to use it.

Would someone be kind enough to please give me pointers on how use our own ... to send information to the site above and get results back to our form?

We are basically trying to get users to enter first initial, lastname, county, date of birth.

Thanks

Chidi Okeh
  • 1,537
  • 8
  • 28
  • 50

1 Answers1

30

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
%>
feetwet
  • 3,248
  • 7
  • 46
  • 84
htbasaran
  • 869
  • 7
  • 10
  • 1
    This code is broken. Parantheses should not be made when calling methods as statements. Also the "POST" example should be setting the Content-Type header. – AnthonyWJones Jul 09 '12 at 12:02
  • Given that I am trying to do this to get data from a site built with asp.net, is this still possible? – Chidi Okeh Jul 09 '12 at 18:59
  • @AnthonyWJones at one point you are right but not at all. I am working with JScript Asp pages so this code is valid for JScript asp but VBScript. Anyway I will edit the answer and remove the parantheses. – htbasaran Jul 09 '12 at 19:52
  • @ChidiOkeh yes, still possible, because this component does not care which technology was used from the source-side, it only cares about the given results by the source. – htbasaran Jul 09 '12 at 19:52
  • it doesn't appear to work for me. Maybe I am using it incorrectly. Can you please gobble up an example of posting form fields to that link and how to get results back from it? – Chidi Okeh Jul 10 '12 at 13:02
  • I added a simple example to my answer. – htbasaran Jul 10 '12 at 13:18
  • Thank you very much sir. I guess my biggest issue is how to pass, say, lastname to the site I posted and get a value back to populate a form. That has been the biggest issue so far. It would not have been that huge of an issue if it wasn't for that fact that that site is an asp.net site. – Chidi Okeh Jul 11 '12 at 19:37
  • Ok! Now I checked your asp.net site and noticed that the site is not returning data we need to handle in our asp page. Its mandatory that the site we send request must response us with valuable data, not redirect us to an another page to get data! It appears that's nothing to do with the technology of the page but the technique :) – htbasaran Jul 12 '12 at 18:45
  • wow, thank you for the detailed answer. Saved me quite a bit of time! From here, I found this MSDN that some helpful samples: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms766431(v=vs.85) – uotonyh Aug 06 '18 at 23:45
  • Can you help me on how to send a POST request passing a Basic authentication? I mean, using ASP VBScript 5.8 – Francisco Souza Mar 06 '20 at 17:27
  • @franzisk, please ask your question in a detailed manner. I will be glad to try to assist you – htbasaran Mar 06 '20 at 20:23
  • @htbasaran don´t bother, I got it working now. Thanks – Francisco Souza Mar 09 '20 at 11:08