【问题标题】:Post request not working on Restful API Codeigniter发布请求在 Restful API Codeigniter 上不起作用
【发布时间】:2016-08-11 15:04:52
【问题描述】:

我在我的 Codeigniter 项目中安装了 RESTful Codeigniter API。当我测试 API 示例并通过 http://textilexports.com/donate/api/example/users url 通过 Chrome 邮递员休息客户端调用时,我在 Post 响应中收到了该错误。

{
    "id": 100
    "name": null
    "email": null
    "message": "Added a resource"
}

public function users_post()
{
    // $this->some_model->update_user( ... );
    $message = [
        'id' => 100, // Automatically generated by the model
        'name' => $this->input->post('name'),
        'email' => $this->input->post('email'),
        'message' => 'Added a resource'
    ];
    $this->set_response($message, REST_Controller::HTTP_CREATED);
}

【问题讨论】:

  • 我也有同样的问题。你解决了这个问题吗?

标签: php codeigniter api rest jsonresponse


【解决方案1】:

我已经在 Firefox 中使用 RESTED 客户端检查了您的 REST API。以下是您传递屏幕截图中提到的参数时的输出。在 chrome 扩展中执行相同操作。

【讨论】:

  • 感谢您的帮助。你能告诉我为什么它不能在 Chrome 上运行(Advance Rest Client)。谢谢img4.imagetitan.com/img.php?image=14_1786.pngimg4.imagetitan.com/img.php?image=14_2343.png
  • 你可以在图片中看到
  • 问题是您试图通过标头信息发送 POST 参数。它是错误的。所以您必须使用数据表单发送 POST 参数。然后一切正常。我也通过 Advanced Rest Client 对其进行了测试.它工作正常。
  • 如何获取 xml 格式的响应数据用于 post call
  • 你好,Dhanu,你可以像这样添加格式参数example.com/books?format=xml你也可以使用json和序列化的PHP输出
猜你喜欢
  • 1970-01-01
  • 2019-01-27
  • 2019-06-26
  • 1970-01-01
  • 2016-01-07
  • 1970-01-01
  • 2020-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多