Skip to content
Advertisement

PHP cURL post data is not sent to target url

Maybe it’s duplicate question. I have tried any solution with similar question with mine that I can find and implemented it to my probs, not a single solution is work. I need to use PHP curl to get data from other systems (B). But in the B the data I sent is not defined or no data was sent. curl process is success target url is just right.

Curl in my system

$data['tag']    = 'getData';
$data['periode'] = $this->input->post('periode');
$url = 'http://example.com/service/index.php';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, sizeof($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// I use follow location cause I get moved permanently notice
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
curl_close($ch);

echo $output;

And in B system I check with this

var_dump($_POST);

the ouput is array(0) {}.

Advertisement

Answer

I have my own solution for this. I just need to set the URL to https insetad of http, because the backend program is redirecting all the non secure protocol http to the secure one https.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement