[Cover] [Previous Section] [Next Section] [Index]
Current chapter: Perl HTTP Utilities
Section 68 out of 79 total sections
, Section 5 out of 5 sections in this chapter
HTTPConnectAndMatch()
Description
Connects an HTTP URL, reads in the page, and returns the first match of the specified regular expression. Accepts a URL and a regular expression. As an option, you can specify the request method (GET or POST). If the method is POST, the last parameter is the content to send to the server. If you do not specify a method, GET is assumed. The regular expression should contain at least one parenthesized expression. Do not include the /-delimiters in the regular expression.
Synopsis
require 'HTTPClient.pl';
...
&AppUtils::HTTPConnectAndMatch($url,
$regExp, $method, $postArgs);
Arguments
|
Argument
|
Meaning
|
$url
|
The URL to use, of the form http://[host[:port]]/[path].
|
$regExp
|
The regular expression to match (without the /-delimiters).
|
$method
|
The request method.
|
$postArgs
|
Arguments for the POST method.
|
Returns
An array that contains the matching values. The array will be undefined if there is an error or no match.
Example
The following code retrieves the KPIX traffic report and prints the line describing conditions on the Carquinez bridge:
#!/usr/local/bin/perl5.001
#
require 'HDMLUtils.pl';
require 'HTTPClient.pl';
$url ="http://www.kpix.com/traffic/ALL.html";
@strs = &AppUtils::HTTPConnectAndMatch($url, "(carquinez.*)");
print @strs;
[Cover] [Previous Section] [Next Section] [Index]
Current chapter: Perl HTTP Utilities
Section 68 out of 79 total sections
, Section 5 out of 5 sections in this chapter
Copyright © 1999, Unwired Planet, Inc. All rights
reserved.