Home  >  Article  >  Backend Development  >  PHP关于file_get_contens函数向本地文件传参数的有关问题

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

WBOY
WBOYOriginal
2016-06-13 13:14:46932browse

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

源码如下:
$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……
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn