Answer the question
In order to leave comments, you need to log in
PHP cURL get request?
Good day, you need to make a request to the API via a GET request, in the body of which json is passed. I understand that the answer is most likely the simplest, but I could not implement this in PHP via cURL.
Let's say I would need to make a POST request, then everything is really simple
$url = 'http://www.example.com/api';
$ch = curl_init($url);
$data = array(
'username' => 'codexworld',
'password' => '123456'
);
$payload = json_encode(array("user" => $data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question