I am making a post request which returns 200
status code on success and works fine when I try it using postman.
When I try to make a POST
request using PHP
, it succeeds but with a 404
status code.
Here is my code.
$url = 'my_url';
$data = array('key1' => 'value1', 'key2' =>
'value2');
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $data ),
'header'=> "Content-Type: application/json\r\n",
'ignore_errors' => true
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
$headers = get_headers($url);
Helper::pre_die($headers);
$code = substr($headers[0], 9, 3);
Here is the header I get:
Array
(
[0] => HTTP/1.1 404 Not Found
[1] => Server: nginx/1.14.0 (Ubuntu)
[2] => Date: Sun, 01 Sep 2019 07:52:34 GMT
[3] => Content-Type: text/html; charset=utf-8
[4] => Content-Length: 146
[5] => Connection: close
[6] => X-Powered-By: Express
[7] => Vary: Origin, Accept-Encoding
[8] => Content-Security-Policy: default-src 'self'
[9] => X-Content-Type-Options: nosniff
)
Any help will be greatly appreciated.