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

Recommended Answers

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@\"}"
Jump to Post

Sory, did not understand the question. Maybe this article can help?

Jump to Post

All 5 Replies

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

Sory, did not understand the question. Maybe this article can help?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.