Jump to content

cURL using POST not working


savagenoob

Recommended Posts

Ive tried everything and cannot get this POST to work, page comes up blank. The output of curlgetinfo() shows:

Array ( [url] => http://app.alliedinsurance.com/find_agent/calcpage4_1_popup.cfm?RequestTimeout=180 [content_type] => text/html; charset=UTF-8 [http_code] => 200 [header_size] => 329 [request_size] => 450 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.172622 [namelookup_time] => 0.02064 [connect_time] => 0.092116 [pretransfer_time] => 0.092244 [size_upload] => 0 [size_download] => 509 [speed_download] => 2948 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.172563 [redirect_time] => 0 ) 

The whole code Im using:

<h2>Please Enter Zip Code</h2>
		<p>
            <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
            <input type="text" size="10" maxlength="10" name="zipcode" tabindex="1" value="<?php echo $_POST['zipcode'];?>" /> <input type="submit" value="Search" name="submit" tabindex="2" />
            </form>
            <br />
<?php
if(isset($_POST['submit']))
{
$zipcode = $_POST['zipcode'];
$userAgent = 'Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1';

$mercurl = "http://app.alliedinsurance.com/find_agent/calcpage4_1_popup.cfm?RequestTimeout=180";
$postcom = "City=&State=AR&ZipCode=" . urlencode($zipcode) . "&Miles=" . urlencode('20') . "&SubmitThis=Submit";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$mercurl);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOP_REFERRER, "http://app.alliedinsurance.com/find_agent/find_an_agent_popup.cfm");
curl_setopt($ch,CURLOPT_POST, 1); 
curl_setopt($ch,CURLOPT_POSTFIELDS,$postcom);

$html = curl_exec($ch);
print_r(curl_getinfo($ch)); 
$html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8');
curl_close( $ch );
echo $html;
?>

Link to comment
Share on other sites

Mate if you would bother to turn error reporting on you would see 2 obvious errors.

 

You misspelled two of the cURL options.

 

 

CURLOP_REFERRER should be CURLOPT_REFERER

CURLOPT_HEADER_OUT does not exist, you already have CURLOPT_HEADER.

 

Fix that then you should see it works.

Link to comment
Share on other sites

Also your retrieval code can be shortened, most of the cURL options are redundant in this case. Plus POST only the minimum required POST fields:

 

$ch = curl_init('http://app.alliedinsurance.com/find_agent/calcpage4_1_popup.cfm?RequestTimeout=180');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://app.alliedinsurance.com/find_agent/find_an_agent_popup.cfm');
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "State=&City=&ZipCode=$_POST[zipcode]");

$html = curl_exec($ch);

Link to comment
Share on other sites

CURLOPT_HEADER_OUT does not exist, you already have CURLOPT_HEADER.

 

Not in it's written form.  It isn't a CURLOPT, but a CURLINFO.

 

CURLINFO_HEADER_OUT TRUE to track the handle's request string. Available since PHP 5.1.3. The CURLINFO_ prefix is intentional.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.