首页 > 解决方案 > 我正在尝试通过邮递员发送数据,但 post 方法什么也没发送

问题描述

$_POST 方法不从邮递员返回数据。

//print_r($POST['Mobile']); (Prints nothing)

if($_SERVER['REQUEST_METHOD']=='POST'){

$response = array();

print_r($_POST['Mobile']);

if ($db->updateCart(
    $_POST['CartData'],
    $_POST['Mobile']
    )) {
    $response['error'] = false;
    $response['message'] = "positive";
}else{
    $response['error'] = true;
    $response['message'] = "Negative";
}

echo json_encode($response);

}

我已经尝试在 print_r 中打印“某些东西”并且效果很好。谁能告诉我我在哪里做错了。

下面是我要发送的邮递员图像。

在此处输入图像描述

标签: phppostman

解决方案


不要使用Params选项卡,而是尝试转到Body并选择form-data,然后在此处输入您的键/值对。

我认为这与 PHP 无关。问题似乎是“参数”选项卡将您的数据作为GET参数而不是POST数据发送。我敢打赌,如果您print_r($_GET)看到您希望在$_POST.

编辑:同时使用参数和正文

可以在两个地方传递设置。考虑:

<?php
/* index.php */
print_r([
  '$_GET' => $_GET,
  '$_POST' => $_POST,
]);

在 Postman 中,只需执行以下操作:

在此处输入图像描述

请注意,Params 中的变量在查询字符串中。


推荐阅读