I'm trying to make a curl through php
below is the command line :
curl -i -H "Accept: application/json" -d "{"username": "divmesselibrary", "password": "677Sure1@"}" https://openlibrary.org/account/login
Please I need your help
I'm trying to make a curl through php
below is the command line :
curl -i -H "Accept: application/json" -d "{"username": "divmesselibrary", "password": "677Sure1@"}" https://openlibrary.org/account/login
Please I need your help
Must be an issue with quotes. Try something like this:
curl -i -H "Accept: application/json" -d '{"username": "divmesselibrary", "password": "677Sure1@"}'
or:
curl -i -H "Accept: application/json" -d "{\"username\": \"divmesselibrary\", \"password\": \"677Sure1@\"}"
how can I convert this to php
Tried the examples in the post you shared but still having issues.
Below is the code:
$data = array("username" => "xxx", "password" => "xxx");
$data_string = json_encode($data);
$ch = curl_init('http://openlibrary.org/account/login');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/javascript',
'Content-Length: ' . strlen($data_string))
);
Thanks.
You have to exec the post. See also example here.
curl_exec($ch);
curl_close($ch);
Also check for errors using curl_error.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.