简体   繁体   中英

Unable to recieve PUT Data using Code Igniter, REST, Lighttpd url-rewrite and Backbone.js

I am using CodeIgniter with REST APIs and Backbone.js. Web server is lighttpd. I also have lighttpd.conf changed for rewriting URLs to remove index.php from urls as follows:-

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

The call from js reaches to Codeigniter Put function but the value for $this->put() is empty. Please help me out in tracing why the value for PUT data is empty.

Note: This works perfectly fine when I don't rewrite the URLs. Also this works for Apache web server.

On debugging REST_Controller.php file, in the function "protected function _parse_put()", I found out that the contents of file "php://input" is also empty

Following is the Request Headers and Payload taken from Chrome Web inspector, while making a PUT Call:-

**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"}

you can use Backbone.emulateJSON = true;

This is the best answer for your doubt :)

Backbone.js PUT/DELETE problems with Codeigniter REST server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM