HTTP Digest Authentication using asiHttpRequest
I am trying to use asiHttpRequest to handle HTTP Digest Authentication, I have two开发者_如何学运维 textfields, one is name and the other is password, when the user login with the correct name and password a label will display the auth and userid response string. Can anyone provide
Here is a sample code of how u can sent request to google for authentication. You can change it for digestion. Hope it helps.
NSString *username = @"my.google.login@gmail.com";
NSString *password = @"mypassword123";
NSString *loginUrl = @"https://www.google.com/accounts/ClientLogin?client=NNW-Mac";
NSString *source = @"NNW-Mac"; //let's fake NetNewsWire
NSString *continueUrl = @"http://www.google.com";
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString: loginUrl]]; // log in & get cookies
[request addRequestHeader: @"User-Agent" value: @"NetNewsWire/3.2b25 (Mac OS X; http://www.newsgator.com/Individuals/NetNewsWire/)"];
[request setPostValue: username forKey: @"Email"];
[request setPostValue: password forKey: @"Passwd"];
[request setPostValue: @"reader" forKey: @"service"];
[request setPostValue: source forKey: @"source"];
[request setPostValue: continueUrl forKey: @"continue"];
[request setDelegate: self];
[request setDidFailSelector: @selector(loginRequestFailed:)];
[request setDidFinishSelector: @selector(loginRequestFinished:)];
[request start];
Edit 1:
NSString *username = @"Login info";
NSString *password = @"Password";
NSString *loginUrl = @"http://connect.twangoo.com";
NSString *continueUrl = @"http://www.google.com";
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString: loginUrl]]; // log in & get cookies
//Dont need it if u dont want to add any header value for the site
//[request addRequestHeader: @"User-Agent" value: @"NetNewsWire/3.2b25 (Mac OS X; http://www.newsgator.com/Individuals/NetNewsWire/)"];
[request setPostValue: username forKey: @"Login"];
[request setPostValue: password forKey: @"Pwd"];
//Just for google api reader service u dont need it here..
//[request setPostValue: @"reader" forKey: @"service"];
[request setDelegate: self];
[request setDidFailSelector: @selector(loginRequestFailed:)];
[request setDidFinishSelector: @selector(loginRequestFinished:)];
[request start];
精彩评论