PHP cURL returns FALSE on HTTPS

I am trying to make a bot for: https://coinroll.it/api

From the website:
The Coinroll API is a stateless interface that works through HTTPS. Requests are made using POST variables (application / x-www-form-urlencoded), while responses are encoded in JSON (application / json). Access to the API requires an HTTPS connection.

I have the following code:

$ch = curl_init(); $data = array('user' => 'xxx', 'password' => 'yyy'); curl_setopt($ch, CURLOPT_URL, 'https://coinroll.it'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); echo $result; 

When I run this code, it returns a blank page, what am I doing wrong?

EDIT
I really don't need to use cURl, if there is a better solution, please tell me.

+4
source share
2 answers

You can prevent cURL from trying to verify the SSL certificate with CURLOPT_VERIFYPEER .

Also set the action in the url:

 $ch = curl_init(); $data = array('user' => 'xxx', 'password' => 'yyy'); curl_setopt($ch, CURLOPT_URL, 'https://coinroll.it/getbalance'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); echo $result; 
+1
source

You can use the following cURL option to find out what happens with the HTTP connection:

 curl_setopt($ch, CURLOPT_VERBOSE, true); 

When TRUE displays detailed information.

+1
source

Source: https://habr.com/ru/post/1489919/


All Articles