HTTP Post in PHP without a Form
For one reason or another I had trouble getting this to work so I thought I would post my code snippet that I used here.
$val) {
$post_str .= $key.'='.urlencode($val).'&';
}
$post_str = substr($post_str, 0, -1);
// Initialize cURL
$ch = curl_init('http://localhost:8888/TargetOfPost.php');
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Execute...
$output = curl_exec($ch);
if (!$output) {
$output = curl_error($ch);
}
curl_close($ch);
// Display the result
return $output;
}
}
?>
No comments yet.