我正在尝试file_get_contents与stream_context_createPOST 一起使用.我的代码到目前为止:
$options = array('http' => array(
'method' => 'POST',
'content' => $data,
'header' =>
"Content-Type: text/plain\r\n" .
"Content-Length: " . strlen($data) . "\r\n"
));
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
Run Code Online (Sandbox Code Playgroud)
它工作正常,但是,当发生HTTP错误时,它会发出警告:
file_get_contents(...): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
Run Code Online (Sandbox Code Playgroud)
并返回false.有办法: