AnkitJ AnkitJ - 7 months ago 61
PHP Question

How to convert https curl into php curl code

I am new to curl and working on project on php. I trying to run curl command on php and my curl command is



curl -I -X POST --header "ttl: 60" "https://updates.push.services.mozilla.com/push/v1/gAAAAABXIvgcjhN-7l1yphdkMoubnwZJdeLKG6cGxG_TeHxZ_BGNDKgoKbhB306PTgvcgFJjurkUI14qIIJ4oZDYyKlJO7oYVZrzyjUI4cKUjtiZlnTXKj0tf9XiXUICtpjRqGqXoMLI"


I had this code to execute this curl as shown below


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('ttl: 60'));

$output=curl_exec($ch);

curl_close($ch);


but not found solution yet. My question is how to convert this curl into php curl


Thanks in advance

Answer

As William suggested add CURLOPT_POST in your code.

$ch = curl_init();  

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('ttl: 60'));
curl_setopt($ch, CURLOPT_POST, true);

$output=curl_exec($ch);
curl_close($ch);

In your curl command -X referring to data type POST or GET and --header or -H is a extra header include in curl.

You can refer curl parameter description for more details on it.

Comments