如何在Codeigniter中获取http请求正文数据? [英] How can I get http request body data in codeigniter?

查看:69
本文介绍了如何在Codeigniter中获取http请求正文数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将JSON编码的数据从IOS obj-c客户端发布到CI控制器。我相信我的问题与此处相同>。但是我在CodeIgniter网站上的请求对象上找不到任何文档。如何查看/解析http请求正文中的数据?

I am having trouble getting JSON encoded data POSTed to my CI controller from my IOS obj-c client. I believe that my problem is the same as the one mentioned here. But I cannot find any documentation on a 'request' object on the CodeIgniter site. How can I view/parse the data in an http request body?

$ this-> request-> body?

$this->request->body ??

谢谢!

推荐答案

我能够通过使用

$jsonArray = json_decode(file_get_contents('php://input'),true); 

以上内容将从输入请求中读取请求正文,然后将JSON解码为关联数组。

The above will read the request body from the input request and then decodes the JSON to an associative array.

如果CI像我上面一样有一个包装来读取输入流http主体数据,我仍然会对重构此代码感兴趣。

I would still be interested in refactoring this code if CI has a wrapper for reading input stream http body data as I am above. Fairly new to this framework.

这篇关于如何在Codeigniter中获取http请求正文数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆