HTTP Tunneling Revealed: Part 1/3 - ASPTear In Action (Page 4 of 6 )
This example shows the basic functionality of authentication and handling post requests using ASPTear. Its written by the manufacturer. Source code for the included file asptearinclude.asp can be found here.
<!-- #include file="asptearinclude.asp" --> <html> <head> <META NAME="generator" CONTENT="Allaire HomeSite 4.0"> <title>Retrieval of POST page</title> </head> <body> <% Dim xObj, strResult, strUrl
' create the object Set xobj = CreateObject("SOFTWING.ASPtear")
On Error Resume Next
' set a referrer, don't cache pages, supply a custom user agent and a timeout xObj.Referrer = "http://www.vatican.va/" xObj.ForceReload = True xObj.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)" xObj.ConnectionTimeout = 45
Some of the less known components include Flicks Software's OCXHttp. It's an MFC written COM component with Installshield to avoid the registration hassle. With full support for GET, HEAD and POST requests, it can be used to set accept headers, user agent, content type, accept ranges, status text, cookies - including multiple cookies on one file, etc. They mention that it uses the Inet control, which others have avoided because of the documented problems with WinInet.dll, I never understood why.
Instantiating and using OCXHTTP is similar and simple as others, but since this article focuses on the evolution of distributed EDI, I think it justifies writing something about every available effort. Similar to others, OCXHTTP has standard GET, POST and HEAD functionality, as well as methods like combineURL, to add relative and base URL formatting into one. It has authentication, and methods like FlagReload / FlagDontCache to handle the caching, session re-use and FlagUseExistingConnect, optimization, custom flags, setting user agent (browser), timeouts and more.
The MSXML Revolution
Microsoft XMLHTTP: Released as part of Internet Explorer 5.0 (and later), or IIS 5 (and later) and created lot of change in the development vision. As a default configured HTTP component, it was stated as "superglue for the web". This suite was originally for the XML DOM manipulation, but it included the XMLHTTP object for URI stream handling. This object was developed extensibly enough to send GET/POST/Head requests and retrieve the XML/HTML or binary data as result. It came as the MSXML 3.0 parser.
Microsoft ServerXMLHTTP: Was actually a replacement for XML HTTP for better performance on busy web servers. It was claimed to make the server more reliable as compared to its precursor.
Below I demonstrate how XMLHTTP can be used for implementing the HTTP GET method -- in this case Google. The mega search engine, Google, if provided with a search phrase in the query string, returns the search results , i.e. http://www.google.com/search?q=web+services where web services is the search phrase.
This example is for educational purposes only. For commercial usage, one must read the terms and conditions for affiliate programs provided:
<%@ Page aspcompat=true %> <% Dim objXMLHTTP, xml ' Create an xmlhttp object: xml = Server.CreateObject("Microsoft.XMLHTTP")
' Version 3.0 of XMLHTTP, use: ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
' Opens the connection to the remote server. xml.Open ("GET", "http://www.google.com/search?q=web+services", False) ' Actually Sends the request and returns the data: xml.Send 'Display the HTML and Text 'Response.Write ("<h1>The HTML text</h1><xmp>") 'Response.Write (xml.responseText) 'Response.Write ("</xmp>") Response.Write ("<h1>This is generated results from google using XMLHTTP </h1>") Response.Write (xml.responseText) xml = Nothing %>
For ServerXMLHTTP, I have an interesting example. BAA Plc provides live flight information for UK airports. If we provide a flight number in the query string, it displays the status of flight i.e. Scheduled time, Coming from, Flight Number, Status and Terminal. In our case it's BA719 from Zurich. The query string seems long, but when I executed it without the airport number, the error result was:
DTWA000E: Net.Data detected an internal error DTWL018E: Net.Data detected a null value in parameter airport in function DTW_UPPERCASE.
... exposing the system modules and those parameter errors that not handled properly. Anyway, the query string with the flight number is shown below: