我想将数据放入PHP输入流php://input
,这样我就可以在调用file_get_contents("php://input");
时将其返回。
我这样做是为了建立一个测试,以确认我无法改变的代码行为。
如何设置php://input
?
答案 0 :(得分:1)
只需让调用PHP的命令在调用命令之前插入输入。
也许使用烟斗?
另外,您可以更改现有代码,使其不从输入中读取,而是从以下参数中读取:
而不是:
map
试试这个:
function current_function(){
$a = file_get_contents("php://input");
# do stuff with $a
}
这有助于使您的设计更具可测性。
另外,如果您无法更改代码,请尝试在bash shell中的PHP脚本中输入内容:
function do_thing_before_current_function($a){
$STDIN = file_get_contents("php://input");
# do stuff to pre-process STDIN
current_function($STDIN);
}
function current_function($a){
# do stuff with $a
}
或者,如果在Windows上,请执行以下操作:
$ echo "input_here" | php your_script_name.php
希望有所帮助!