我用rails new demo
做了一個演示應用程序,然後用rails generate scaffold User name:string email:string
生成了一個腳手架的用戶控制器。腳手架代碼有ApplicationController
和protect_from_forgery
,UserController
也源自ApplicationController
。protect_from_forgery不保護PUT/DELETE請求
我運行webrick,添加一個用戶,很酷。真實性標記按照POST/on用戶承諾的方式工作。
但仍使用Rails 3.0.5,我能夠做到:
[email protected]:~$ telnet 10.0.0.4 3000
PUT /users/3 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
user[name]=vvvvv&user[email]=shiaus.pl
,並讓用戶修改3不給令牌:
Started PUT "https://stackoverflow.com/users/3" for 10.0.0.4 at 2011-04-02 14:51:24 +0200
Processing by UsersController#update as HTML
Parameters: {"user"=>{"name"=>"vvvvv", "email"=>"shiaus.pl\r"}, "id"=>"3"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
', "updated_at" = '2011-04-02 12:51:24.437267' WHERE "users"."id" = 3s.pl
Redirected to http://10.0.0.4:3000/users/3
Completed 302 Found in 92ms
我也可以做同樣的DELETE:
DELETE /users/3 HTTP/1.1
這給了我:
Started DELETE "https://stackoverflow.com/users/3" for 10.0.0.4 at 2011-04-02 15:43:30 +0200
Processing by UsersController#destroy as HTML
Parameters: {"id"=>"3"}
SQL (0.7ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
AREL (0.5ms) DELETE FROM "users" WHERE "users"."id" = 3
Redirected to http://10.0.0.4:3000/users
Completed 302 Found in 180ms
您能否向我解釋爲什麼我從來不會在這些請求旁邊發送任何令牌?