开发者

I want to know how to login to a rails 3 server with the following parameters through iphone

开发者 https://www.devze.com 2023-03-30 04:58 出处:网络
I want my request to look and have this effect in the rails server: Started POST \"/users/sign_in\" for 127.0.0.1 at 2011-08-21 16:22:09

I want my request to look and have this effect in the rails server:

Started POST "/users/sign_in" for 127.0.0.1 at 2011-08-21 16:22:09
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"mBzfQ73jtZ9rlj01+RCSs6mJoViFQZuRbwunQiX57oU=", "user"=>{"email"=>"a@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'a@gmail.com' LIMIT 1
(0.4ms)  UPDATE "users" SET "last_sign_in_at" = '2011-08-21 23:18:50.886178', "current_sign_in_at" = '2011-08-21 23:22:09.698853', "sign_in_count" = 7, "updated_at" = '2011-08-21 23:22:09.699635' WHERE "users"."id" = 1
Redirected to http://localhost:3000/user
Completed 302 Found in 206ms

BUT my request looks something like this:

Started POST "/users/sign_in" for 127.0.0.1 at 2011-08-21 16:19:56
Processing by Devise::SessionsController#create as HTML
Parameters: {"commit"=>"Sign in", "password"=>"[FILTERED]", "email"=>"a@gmail.com", "remember_me"=>"1", "session"=>{"commit"=>"Sign in", "password"=>"[FILTERED]", "email"=>"a@gmail.com", "remember_me"=>"1", "action"=>"create", "controller"=>"devise/sessions"}}
WARNING: Can't verify CSRF token authenticity
Completed   in 1ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"commit"=>"Sign in", "password"=>"[FILTERED]", "email"=>"a@gmail.com", "remember_me"=>"1", "session"=>{"commit"=>"Sign in", "passwor开发者_如何学运维d"=>"[FILTERED]", "email"=>"a@gmail.com", "remember_me"=>"1"}}
WARNING: Can't verify CSRF token authenticity
Rendered /Users/hdj/.rvm/gems/ruby-1.9.2-p290@rails31/gems/devise-1.4.2/app/views/devise/shared/_links.erb (1.6ms)
Rendered /Users/hdj/.rvm/gems/ruby-1.9.2-p290@rails31/gems/devise-1.4.2/app/views/devise/sessions/new.html.erb within layouts/application (25.4ms)
Completed 200 OK in 162ms (Views: 94.0ms | ActiveRecord: 0.9ms)

which im sure doesnt log me in. The cocoa obj C code im using is this:

NSString *urlString = @"http://localhost:3000/users/sign_in";
NSDictionary *thestuff = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"a@gmail.com", @"email", 
                          @"123456", @"password",
                          @"1",@"remember_me",
                          @"Sign in", @"commit",nil];
NSString *tojson = [thestuff JSONRepresentation];
//NSLog(@"%@        %@", thestuff, tojson);
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlString]];
[request appendPostData:[tojson dataUsingEncoding:NSUTF8StringEncoding]];
[request addRequestHeader:@"Content-Type" value:@"application/json"];

[request startSynchronous];

Im using synchronous simply because i need the user to be logged in before i move on to the next view. Another thing is that i am not sure how to send the username and password titled as email and password as you can see from the request. So im using a json form. Essentially I would like to know how I can change this code to have the desired result. Also, is there a way to send the data in HTML form instead of using the json as I have used here? I would really appreciate help here and if you need more code, Id be happy to provide it.


You need this after you created the ASIHTTPRequest!

[request addRequestHeader:@"Content-Type" value:@"application/json"];
0

精彩评论

暂无评论...
验证码 换一张
取 消