1
$newLogUrl = SERVER URL PATH
$opt = array('http' => array(
             'method'  => "POST",
             'header'  => 'Content-type: application/json',
             'content' => $jsonCredenObj,
             'timeout' => 4));
$context = stream_context_create($opt);

$response = file_get_contents($newLogUrl,false,$context); 

The above code is working in the normal http but not working in the secure server https

The Error

Warning: file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
Arun Krishnan
  • 1,898
  • 3
  • 16
  • 28

1 Answers1

3

405 Method Not Allowed

The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource. Also as MarcB mentioned , the corresponding URL you are connecting does not accept the POST method.

Source : www.w3.org

Always check the URL for headers to see what methods they accept and etc.. you could make use $http_response_header for that..

<?php
file_get_contents('http://thatremoteurl.com');
var_dump($http_response_header);

Working with HTTPs URLs

You need to enable openssl extension on your PHP.ini.

Open your PHP.ini and check for this line ;extension=php_openssl.dll . Remove the semicolon before it and save your file and restart your webserver.

Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126