I'm stumped. I'm playing around with curl trying to fill out a form. I decided to try out the USPS zip code search. http://zip4.usps.com/zip4/welcome.jsp and try to find the Whitehouse zip code.
Seems easy enough, right?
Well, I'm missing something important because the form processor returns "temporarily unavailable" always. It wont work for me. What am I doing wrong? I've done everything I think I need to be doing.
thanks 🙂
<?PHP
$cookie_file_path = "cookies/cookiejar.txt"; // Please set your Cookie File path
$fp = fopen("$cookie_file_path","w") or die("<BR><B>Unable to open cookie file $mycookiefile for write!<BR>");
fclose($fp);
//load form page.
$ch = curl_init();
$url = "http://zip4.usps.com/zip4/welcome.jsp";
curl_setopt($ch, CURLOPT_URL, $url);
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
print $result;
//load page result page.
$url = "http://zip4.usps.com/zip4/zcl_0_results.jsp";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
$mypostfields = urlencode("visited=1&pagenumber=0&address2=1500 PENNSYLVANIA AVE&city=WASHINGTON&state=DC");
curl_setopt($ch, CURLOPT_POSTFIELDS, $mypostfields);
$result = curl_exec ($ch);
print $result;
curl_close($ch);
?>