返回404状态代码的PHP POST请求
我正在发出一个post请求,它在成功时返回返回404状态代码的PHP POST请求,php,http,post,request,Php,Http,Post,Request,我正在发出一个post请求,它在成功时返回200状态代码,当我使用postman尝试时,效果很好 当我尝试使用PHP发出POST请求时,它成功了,但状态代码为404 这是我的密码 $url = 'my_url'; $data = array('key1' => 'value1', 'key2' => 'value2'); $options = array(
200
状态代码,当我使用postman尝试时,效果很好
当我尝试使用PHP
发出POST
请求时,它成功了,但状态代码为404
这是我的密码
$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);
这是我得到的标题:
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
)
任何帮助都将不胜感激。如果它在postman上工作,为什么不直接从postman获取curl代码并将其复制到php文件中呢。请参阅此处的链接。
$url
中有任何特殊字符吗?@Don'tPanic no。我们无法帮助您,因为这是不可复制的。我知道了。我用错了get_头($url)。它应该是get_头($url,1,$context);