![]() |
|
|
How do I use MSXML2.ServerXMLHTTP to grab data from another site?
You can use this component for http-requests like "POST", "GET", "DELETE" etc.
<% ' 0: create the object: ' ---------------------------------------------------------------------------------------------------------------------- Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP") ' 1: 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.) ' 2: send data using method "POST": ' ---------------------------------------------------------------------------------------------------------------------- NON E' PROPRIO COSI': SI DEVONO METTERE I PARAMETRI IN LINEA CON ? 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. ' 3: 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 %>