【发布时间】:2012-10-09 02:15:56
【问题描述】:
如何修复 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;
?>
【问题讨论】:
-
你试过像
$callback = @file_get_contents($apiUrl); if($callback !== false) print_r($callback);一样吗? -
如果您在浏览器中访问该 URL 会发生什么?你重定向了吗?尝试使用 CURL 并查看标头返回的内容。
-
stackoverflow.com/questions/12489499/… 用于类似的 CURL 代码。
-
使用 CURL (php.net/manual/en/book.curl.php)
标签: php file-get-contents