Я могу подключиться к API без каких-либо проблем, поэтому я могу видеть, как генерируется токен, но я не уверен, как лучше сохранить токен при использовании curl с php и json, поэтому я могу продолжать авторизоваться с помощью лексема
<?php
//API Url
$url = 'https://sample.api.com';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'username' => 'usernamegoeshere.',
'password' => 'passwordgoeshere'
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
Essentially I get to view / see the token that has been generated
For example:
{"token":"00000000"
Однако я не уверен, как я могу продолжать использовать сгенерированный токен, чтобы перейти к следующему URL-адресу API, чтобы сделать еще один пост / get