HTTP-LIB.PL Updates.
I've made some updates to the library http-lib.pl to support proxied GETs, POSTs and HEADs.
I also cleaned up the code to use fewer throw away buffers, save the retrieved header in $httpHead
and the error code in $httpErrorCode. When an error occurs the HTTP buffer contains the HTTP header's
first line that should contain the human readable error. Here's where to get it:
The proxy support is enabled by calling HTTPProxy ($host, $port); where host is the IP address
that the proxy request will be sent to.
The actual routines available are:
- $buf = HTTPPost ($fileName, $site, $port, $queryString);
- $buf = HTTPGet ($fileName, $site, $port, $queryString);
- $buf = HTTPHead ($fileName, $site, $port, $queryString);
Where:
- $fileName = the full pathname of the file to retrieve. Use '/' for the root directory.
- $site = name or IP address that the proxy will process (ie. the IP address to GET data from).
- $port = the site's HTTP port, usually 80, but sometimes 8080, 8008 etc.
- $queryString = String holding name/value pairs in the form:
name=value[&name=value]...
For example 'x=23&y=44' could be used to simulate a click on an image.
Here's some sample code that gets the data from URL
http://www.anzwers.com.au:$80/index.htm?isbn=0201634627
using the proxy wingate:80 that's local to my network ...
$proxyHost = 'wingate';
$proxyPort = 80;
&HTTPProxy ($proxyHost, $porxyPort);
$port = 80;
$site = 'www.anzwers.com.au';
$queryString = "isbn=0201634627";
$fileName = "/index.htm";
$buf = &HTTPGet ($fileName, $site, $port, $queryString);
unless ($httpErrorCode) {
print 'DATA ->\n' . $buf . '<- END\n';
}
Needless to say, you should plug in real values in the example above.
I intend to enhance this code to:
- Handle 302 MOVED HTTP status returns by doing an automatic redirection.
- Handle If-Modified-Since: in the request header to get around local proxy caching.
- Save and return (or not!) cookies for sites that need them.
- Write a simple caching proxy server just for the hell-of-it.
- Incorporate suggestions...
Any questions, suggestion, etc. Mail me, Peter Gargano, at
peter@mail.techedge.com.au and flame, complain or ...
Last modified 17th June 1998, copyright © Peter Gargano 1998.