Using the
XMLHTTP Object
to
Get Text, Binary, or Post Data
Code:
HTML Text
Highlight
<% function getText() Dim objXMLHTTP, xml Set xml = Server.CreateObject("Microsoft.XMLHTTP") ' For version 3.0 of XMLHTTP, use: ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP") xml.Open "GET", "http://www.4Guysfromrolla.com/", False xml.Send Response.Write xml.responseText Set xml = Nothing end function %>
Binary Data
Highlight
<% function GetBinary() Dim objXMLHTTP, xml Set xml = Server.CreateObject("Microsoft.XMLHTTP") ' For version 3.0 of XMLHTTP, use: ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP") xml.Open "GET", "http://www.4guysfromrolla.com/webtech/code/mitchell-pres.zip", False xml.Send Response.AddHeader "Content-Disposition", "attachment;filename=mitchell-pres.zip" Response.ContentType = "application/zip" Response.BinaryWrite xml.responseBody Set xml = Nothing end function %>
Post Data
Highlight
<% function postData() Dim objXMLHTTP, xml Set xml = Server.CreateObject("Microsoft.XMLHTTP") ' For version 3.0 of XMLHTTP, use: ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP") xml.Open "POST", "http://www.imdb.com/Find", False xml.Send "select=All&for=The Usual Suspects" Response.Write xml.responseText Set xml = Nothing end function %>