Home > Software engineering >  Example with parameter curl -x php
Example with parameter curl -x php

Time:07-23

I have to make a curl request in php with these parameters, can you help me with an example, since I can't find anything similar

the link curl

curl -X GET "https://example.com/nms/api/v2.1/devices?withInterfaces=true&authorized=false&type=uisps&role=switch" -H "accept: application/json" -H "x-auth-token: wsedr4455-3345-es45-2345-4edeesssd"

CodePudding user response:

You should transform it into PHP curl syntax. It should work like this:

$ch = curl_init('https://example.com/nms/api/v2.1/devices?withInterfaces=true&authorized=false&type=uisps&role=switch');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'accept: application/json',
    'x-auth-token: wsedr4455-3345-es45-2345-4edeesssd'
));
$result = curl_exec($ch);
curl_close($ch);

The JSON incoming is in $result.

  • Related