日期:2014-05-17  浏览次数:20399 次

PHP关于file_get_contens函数向本地文件传参数的问题
PHP关于file_get_contens函数向本地文件传参数的问题

源码如下:
<?php
$str_query = "userId=admin&gameId=game1&serverId=server1";


$context= stream_context_create(array(
'http'=> array(
'method'=> 'POST',
'timeout' => 10,
'header'=> 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13\r\nContent-type: application/x-www-form-urlencoded\r\n',
'content'=> $str_query
)
));

echo file_get_contents("interface.php",true, $context);

?>

本地Aparche服务器上就两个文件。一个是放以上源码的文件。一个是interface.php文件。

我在此文件上写上如上的源码。用file_get_contents向interface.php文件POST数据。结果interface.php没有接收到数据。

不知道是在哪里出错了。求高手赐教!!!!

------解决方案--------------------
这点参数直接curl get 就是了
------解决方案--------------------
探讨

引用:
另外参数数组中
header 项要写成
'header'=> "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13\r\nContent-type: app……