【问题标题】:Codeigniter get json encoded bodyCodeigniter 获取 json 编码的正文
【发布时间】:2015-11-11 13:33:51
【问题描述】:

我正在使用带有 REST_Controller 库的 codeigniter。到目前为止,我一直在使用$this->input->post() 来获取 POST 请求发送的值。

但是,一些值在正文中作为 json 编码字符串发送,我无法通过 $this->input->post() 看到这些值

现在我可以使用 file_get_contents('php://input') 访问 json 字符串,但这种方式开箱即用似乎并不安全,我发现 codeigniter 不太可能无法解决这个问题。

所以我的问题是:file_get_contents('php://input') 真的是在 codeigniter 中访问这些变量的唯一方法,还是有更多框架定义的方法来做到这一点?

【问题讨论】:

    标签: php json codeigniter


    【解决方案1】:

    请求是由 PUT 发送的,这就是 CI 不使用 post() 接收它的原因。

    file_get_contents('php://input')是code igniter中访问HTTP PUT的唯一方式;但是,this extensions 的 CI_Input 将处理 HTTP PUT。

    【讨论】:

      猜你喜欢
      • 2017-07-27
      • 2021-12-31
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      相关资源
      最近更新 更多