PLEASE note: These pages are here solely for historic purposes. New articles have not been written since 2001; many links in the index are broken; and most ahref.com email addresses will now bounce. Try visiting ep Productions, Incorporated, the web programming and development company behind this site.

Tip: Want to know when we post new content? Subscribe to our newsletter.

web index ahref.com: a community space for web developers------ -----
IndexToolsCareersTalk
ahref.com > Guides > Technology

Technology Guide

Building a Site Submission Program, Continued

Making the Submissions

Lines 80-99 do most of the work of the program.

 80 foreach $sitename (@site_list) {
 81   $query_string = $$sitename{submission_page} . "?";
 82   foreach $key (keys %$sitename) {
 83     if (($key ne "submission_page") && ($key ne "success")){
 84       $query_string .= "$key=$$sitename{$key}&";
 85     }
 86   }
 87   my $request = new HTTP::Request 'POST', $query_string;
 88   my $response = $ua->request ($request);
 89   $response_body = $response->content();
 90   if (($response->code() == RC_OK) && ($response_body =~ /$$sitename{"success"}/)) {
 91     $output_string .= "<BR>Submission to <B>$sitename</B> was successful.\n<HR>\n";
 92   }
 93   else {
 94     $coder = $response->code();
 95     $output_string .= "<BR>Submission to <B>$sitename</B> failed for some reason. ";
 96     $output_string .= "(Response code $coder.) ";
 97     $output_string .= "You will need to submit to $sitename by hand.\n<HR>\n";
 98   }
 99 }

At line 80, we start cycling through our list of search engines. Line 81 begins the construction of our query string, the full URL that we will be accessing in making our submission. We start the URL with the base URL of the search engine's submission page, and add on a question mark, to show that what follows is a series of variable names and values. At line 82, we start cycling through the key/value pairs in the current search engine's hash. Line 83 checks if the key/value pair is one that does not contain information on a variable and value for constructing the query string. If it does not contain needed information, we go back to line 82, and access the next key and value. Otherwise, on line 84, we add the variable and value to the query string, along with an ampersand in case there are more variables to add.

Line 87 creates an HTTP::Request object, and line 88 performs the request and assigns the response to $response. Line 89 assigns the HTML from the response - the HTML you would normally see after submitting the form - to $response_body. Line 90 confirms that nothing went wrong. If there were no errors indicated by the HTTP header (we check $response->code() for this information), and the HTML which was returned includes the "success" text which we assigned to the hash, line 91 is executed. Text indicating that the submission to this search engine was successful is added to the program's output. If there was an error, or the HTML did not include the "success" text, lines 94-97 are executed. We determine the HTTP response code on line 94, and add text indicating that there was a problem with the submission to the program's output.

continue reading >>>
or jump to a topic:

Introduction
Preliminaries
Input Validation
Defining the Search Engines
More Variable Setup
Making the Submissions
Finishing Up
Things to Keep in Mind


view a printable version of this article


To suggest a topic, please email guides@ahref.com.

 


HOME ||| ABOUT AHREF.COM ||| ADVERTISE ||| FEEDBACK ||| SEARCH THIS SITE ||| CONTRIBUTE

© 1998-1999 ep Productions, Inc. All rights reserved. Terms of use.