codeigniter 代码触发器$this->input->post()返回NULL

v1l68za4  于 2023-03-06  发布在  其他
关注(0)|答案(2)|浏览(110)

在CodeIgniter中创建Sign UpAPI时,我尝试使用内置的this-〉input-〉post('name ')函数,但this-〉input-〉post()返回一个空数组。
我在浏览器上使用
相同的url
,它在那里工作得很好,但当我尝试在Postman上使用它时,它返回null
我试过:
打印_r($_ POST)。
我还使用了POST和GET方法,但没有显示任何内容。
这也给出了null
出于测试的目的,我创建了一个函数,在其中使用form和post方法发送数据,该函数在浏览器上运行良好,但在Postman上没有显示任何内容。

**TESTING Function**
public function test()
{
    echo '<form method="POST"> <input name="name" ><input type="submit"> </form>';
    // print_r($_POST);
    die(var_dump($_POST));
}

svmlkihl

svmlkihl1#

验证您的Postman请求正文:确保你在请求正文中发送了正确的数据。你可以通过打开Postman中的“正文”标签并检查“表单-数据”键值对或“原始”正文来检查这一点。
检查您的CodeIgniter代码:确保CodeIgniter代码已正确配置为接受POST请求。在CodeIgniter中,可以使用$this-〉input-〉post()函数从POST请求中检索数据。确保正确使用此函数,并且CodeIgniter控制器已正确设置。
检查您的Postman请求标题:确保请求标头包含Content-Type:应用程序/x-www-格式-网址编码或内容类型:multipart/form-data。这告诉服务器您正在发送表单数据。
调试CodeIgniter代码:您可以在CodeIgniter控制器中添加var_dump($_POST)或var_dump($this-〉input-〉post())来查看数据是否正确发送和接收。如果仍然有问题,您可以使用CodeIgniter的调试工具来帮助您诊断问题。

1tu0hz3e

1tu0hz3e2#

CodeIgniter在获取application/json post值时有时会表现得很疯狂。

$_POST = file_get_contents('php://input');

您将获得一个从Postman接收到的post值数组,其标头为Content-type: application/json

相关问题