无法使用Codeigniter,REST,Lighttpd url-rewrite和Backbone.js接收POST数据

时间:2013-02-08 06:18:34

标签: codeigniter rest backbone.js lighttpd

我正在使用带有REST API和Backbone.js的CodeIgniter。 Web服务器是lighttpd。我还更改了lighttpd.conf以重写URL以从url中删除index.php,如下所示: -

url.rewrite-once = (
 "/(.*)\.(.*)" => "$0",
 "/(css|files|img|js|stats)/" => "$0",
 "^/([^.]+)$" => "/index.php/$1"
)

来自js的调用到达Codeigniter Put函数但$ this-> put()的值为空。请帮我跟踪为什么PUT数据的值为空。

注意:当我不重写URL时,这完全正常。这也适用于Apache Web服务器。

在调试REST_Controller.php文件时,在函数“protected function _parse_put()”中,我发现文件“php:// input”的内容也是空的

以下是从Chrome Web检查员处获取的请求标头和有效负载,同时进行PUT呼叫: -

**Request Headers**
PUT http://10.82.0.160/cav_settings/api/2 HTTP/1.1
Pragma: no-cache
Origin: http://10.82.0.160
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17
Content-Type: application/json
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://10.82.0.160/settings/2
X-Requested-With: XMLHttpRequest
**Request Payload**
{"aggregation":{"enabled":"false","mode":""},"dns":{"auto":"false","servers":["10.0.0.5","10.20.0.20"]},"id":"2","dhcp":"false","ip":"10.82.0.160","netmask":"255.255.255.0","default_gw":"","mtu":"1500"}

1 个答案:

答案 0 :(得分:0)

你可以使用Backbone.emulateJSON = true;

这是您怀疑的最佳答案:)

Backbone.js PUT/DELETE problems with Codeigniter REST server