FortiGate 200B-POE API Poll (PHP Preserving Cookies)

I have been helping Ivan with trying to preserve cookies while polling the web service for a json response of the router’s status. As there are not much tutorials or sample codes provided by the vendor, I hope the code below explains how it can be done in PHP.

'timeout' => 25,
'header'=>"Accept-language: en\r\n"
$context = stream_context_create($opts);
$xm = file_get_contents($request, false, $context);

$johncookie = $http_response_header[2];
$john = explode("APSCOOKIE_2464548051=", $johncookie);

$req = "{'vdom':'root','path':'router','name':'ipv4','action':'select','start':'0','count':'1000'}";
$opts = array(
'timeout' => 25,
"Cookie: APSCOOKIE_2464548051=" . $john[1] . "\r\n"
$context = stream_context_create($opts);
$xml = file_get_contents($req, false, $context);

echo htmlspecialchars($xml, ENT_QUOTES);


Hope it helps some of you 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: