Sie sind hier

Error 405 while quering API

1 post / 0 new
raz3r
Bild des Benutzers raz3r
Error 405 while quering API

Hi everyone, through PHP I successfully retrieved a token for authentication but I can't seem to find a way to query API after that. Here is a code snippet:

// Get Token (this code actually works)

$params = array ('username' => '******', 'password' => '******'); $query = http_build_query ($params); $contextData = array ('method' => 'POST','header' => "Connection: close\r\n"."Content-Length: ".strlen($query)."\r\n",'content'=> $query ); $context = stream_context_create (array ( 'http' => $contextData )); $result =  file_get_contents ('http://*.*.*.*/rest/login',false,$context); $token = json_decode($result); $token = $token->{'token'};   // Get Info now that I have a token (this code DOES NOT work)   $contextData = array ('method' => 'POST','header' => "Content-Type: application/json\r\n"."Connection: close\r\n"."X-Opsview-Username: ******\r\n"."X-Opsview-Token: ".$token."\r\n"); $context = stream_context_create (array ( 'http' => $contextData )); $result =  file_get_contents ('http://*.*.*.*/rest/status/hostgroup',false,$context);   I think problem resides on the header but I am not entirely sure, this is the error I receive:   Warning: file_get_contents(http://*.*.*.*/rest/status/hostgroup): failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed in C:\xampp\htdocs\***\***.php on line 102   FYI line 102 is the last one on the code snippet.   Any hints? Thank you.