如何修复 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
这是与 $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;
?>
最佳答案
如果这显示在您的页面中,则说明您的 display_errors
有问题设置。
理想情况下,对于生产机器,display_errors
应该是 Off
并且您应该使用 set_error_handler()
自行处理错误.
另请参阅:Error logging, in a smooth way
除非您确保该页面存在,否则无法停止此特定警告。但是,单独使用时,您可以使用 muffle operator防止出现警告:
if (false !== ($contents = @file_get_contents('...'))) {
// all good
} else {
// error happened
}
请注意,这仍会调用您的自定义错误处理程序
关于php - 如何修复 php 警告 : file_get_contents? 无法打开流:HTTP 请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12791974/