如何修复php警告:file_get_contents?无法打开流:HTTP请求失败

小弟调*_*弟调调 4 php file-get-contents

如何修复php警告:file_get_contents?

Warning: file_get_contents(http://192.168.1.254:9999/api/p/internal/ucenter/login?loginName=test102&password=111111) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /Applications/XAMPP/xamppfiles/htdocs/PHP_test/index.php on line 49
Run Code Online (Sandbox Code Playgroud)

这是与$ files相关的代码:

<?php
$loginNames="test102";
$passwords="111111";
$apiUrl = "http://192.168.1.254:9999/api/p/internal/ucenter/login?loginName=".$loginNames."&password=".$passwords;
$callback = file_get_contents($apiUrl);

print_r($callback);
//echo $callback;
?>
Run Code Online (Sandbox Code Playgroud)

Ja͢*_*͢ck 11

如果在您的页面中显示,则说明您的display_errors设置有问题.

理想情况下,display_errors应该是Off生产机器,你应该自己处理错误set_error_handler().

另请参阅:错误记录,以平滑的方式

除非确保页面存在,否则无法停止此特定警告.但是,隔离使用,您可以使用马弗操作器来防止出现警告:

if (false !== ($contents = @file_get_contents('...'))) {
    // all good
} else {
    // error happened
}
Run Code Online (Sandbox Code Playgroud)

请注意,这仍将调用您的自定义错误处理程序