php中出现Notice: Undefined index: HTTP_RAW_POST_DATA in D:Program Files
程序员文章站
2022-05-18 09:32:03
...
我在php中写下了:
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
运行后
php中出现Notice: Undefined index: HTTP_RAW_POST_DATA in D:\Program Files\phpEnv\phpdemo\shm_php01\shm01.php on line 47
然后我把php.ini文件中的always_populate_raw_post_data = On 注释去掉了
; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
; to disable this feature. If post reading is disabled through
; enable_post_data_reading, $HTTP_RAW_POST_DATA is *NOT* populated.
; http://php.net/always-populate-raw-post-data
always_populate_raw_post_data = On
重启依然不能用,求高人指点迷津
我的源代码方法是这样的:
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$postObj = simplexml_load_string($HTTP_RAW_POST_DATA, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "
%s
0
";
if($keyword == "?" || $keyword == "?")
{
$msgType = "text";
$contentStr = date("Y-m-d H:i:s",time());
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
}else{
echo "";
exit;
}
}
帮我看下
我用这个方法试了下,这样直接return了。。然后下面的代码就没有实现了。。不晓得咋弄了
可能我还不是很会,那我在学学,谢谢了
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
运行后
php中出现Notice: Undefined index: HTTP_RAW_POST_DATA in D:\Program Files\phpEnv\phpdemo\shm_php01\shm01.php on line 47
然后我把php.ini文件中的always_populate_raw_post_data = On 注释去掉了
; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
; to disable this feature. If post reading is disabled through
; enable_post_data_reading, $HTTP_RAW_POST_DATA is *NOT* populated.
; http://php.net/always-populate-raw-post-data
always_populate_raw_post_data = On
重启依然不能用,求高人指点迷津
回复讨论(解决方案)
always_populate_raw_post_data = On
当以 post 方式提交时,可用
echo $HTTP_RAW_POST_DATA;
打印出提交过来的无格式串
当然不是 post 方式提交时,就是未定义
其实这本可以用 file_get_contents('php://input') 代替的
always_populate_raw_post_data = On
当以 post 方式提交时,可用
echo $HTTP_RAW_POST_DATA;
打印出提交过来的无格式串
当然不是 post 方式提交时,就是未定义
我的源代码方法是这样的:
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$postObj = simplexml_load_string($HTTP_RAW_POST_DATA, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "
if($keyword == "?" || $keyword == "?")
{
$msgType = "text";
$contentStr = date("Y-m-d H:i:s",time());
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
}else{
echo "";
exit;
}
}
帮我看下
public function responseMsg() {
if(! isset($GLOBALS["HTTP_RAW_POST_DATA"])) return '';
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
public function responseMsg() {
if(! isset($GLOBALS["HTTP_RAW_POST_DATA"])) return '';
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
我用这个方法试了下,这样直接return了。。然后下面的代码就没有实现了。。不晓得咋弄了
直接运行,当然是直接返回
要是 post 提交的才行
直接运行,当然是直接返回
要是 post 提交的才行
可能我还不是很会,那我在学学,谢谢了
测试时,你得写个表单
这个是微信接口里面的代码吧 我也出现这个问题 楼主解决了吗