Khi tôi cố gắng POST từ RestKit
, có một cảnh báo trong Rails console:Rails lãm "CẢNH BÁO: Không thể xác minh tính xác thực CSRF mã thông báo" từ một RestKit POST
Started POST "/friends" for 127.0.0.1 at 2012-04-16 09:58:10 +0800
Processing by FriendsController#create as */*
Parameters: {"friend"=>{"myself_id"=>"m001", "friend_id"=>"f001"}}
WARNING: Can't verify CSRF token authenticity
(0.1ms) BEGIN
SQL (1.7ms) INSERT INTO `friends` (`friend_id`, `myself_id`) VALUES ('f001', 'm001')
(1.1ms) COMMIT
Redirected to http://127.0.0.1:3000/friends/8
Completed 302 Found in 6ms (ActiveRecord: 3.0ms)
Dưới đây là mã khách hàng:
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject: @"f001" forKey: @"friend_id"];
[attributes setObject: @"m001" forKey: @"myself_id"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:attributes forKey:@"friend"];
[[RKClient sharedClient] post:@"/friends" params:params delegate:self];
Làm cách nào để thoát khỏi cảnh báo?
Để tránh mở lỗ lớn, tôi khuyên bạn nên bỏ qua xác minh chỉ dành cho phương pháp của mình. 'skip_before_filter: verify_authenticity_token: only => [: your_method]' –
để cắt và dán đoạn mã trên: 'skip_before_filter: verify_authenticity_token,: only => [: your_method]' Marc quên dấu phẩy. KHÔNG thấy nút chỉnh sửa. – pjammer
Cảm ơn thông tin chi tiết này .. –