2

我正在尝试从 iOS 应用程序注册到 rails 后端。

rake routes

告诉我:

user_registration     POST   /users(.:format)         devise/registrations#create
new_user_registration GET    /users/sign_up(.:format) devise/registrations#new

所以在iOS端我正在尝试这个:

NSDictionary *parameters = @{
                             @"email": username,
                             @"password": password,
                             @"password_confirmation": passwordConfirmation
                             };

[[ADCAPIClient sharedClient] postPath:@"users"
                          parameters:parameters
                             success:^(AFHTTPRequestOperation *operation, id responseObject)

我收到一个未知格式异常:

Started POST "/users" for 192.168.178.21 at 2013-11-02 18:53:08 +0100
Processing by Devise::RegistrationsController#create as JSON
Parameters:
{"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"abc@def.de",
"registration"=>{"password"=>"[FILTERED]", "password_confirmation"=>
"[FILTERED]", "email"=>"abc@def.de"}}

Can't verify CSRF token authenticity
(0.1ms)  BEGIN
(0.1ms)  ROLLBACK
Completed 406 Not Acceptable in 6ms

ActionController::UnknownFormat (ActionController::UnknownFormat):

如果我通过浏览器中设计生成的视图进行连接,它可以工作并且它发送的请求如下所示:

Started POST "/users" for 127.0.0.1 at 2013-11-03 10:58:54 +0100
Processing by Devise::RegistrationsController#create as HTML
Parameters:
{"utf8"=>"✓", "authenticity_token"=>"xxxx", "user"=>{"email"=>"abc@def.de", "password"=>
[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.2ms)  BEGIN
...

我是第一次进行客户端后端通信,所以我无法弄清楚正确的请求是什么样的?!我已经搜索了stackoverflow,但答案非常不令人满意。有人可以帮助我或为我提供一个很好的解释或教程的链接吗?提前致谢!

4

0 回答 0