Как запустить graphql api в php, используя запрос curl post - PullRequest
0 голосов
/ 22 марта 2019

Это функция cURL, которая может отправлять или извлекать данные.Он должен работать с любым приложением PHP, которое поддерживает OAuth:

function jwt_request($url,$token, $post) {
    header('Content-Type: application/json'); // Specify the type of data
    $ch = curl_init($url); // Initialise cURL
    $post = json_encode($post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1); // Specify the request method as POS
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); // Set the posted fields
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // This will follow any redirects
    $result = curl_exec($ch); // Execute the cURL statement
    curl_close($ch); // Close the cURL connection
    return ($result); // Return the received data
}
// I am running in localhost
$url = "http://localhost:3000/graphql";
// This is what query i am running
$post = '{"query": "query { login(username:"abbas@gmail.com",password: "abbas") { userID token } }" }';
// This is the function i am using in above
$json = jwt_request($url,$token, $post);
echo "<pre>"; 
print_r($json); // here printing
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...