1
我想用asiHttpRequest來處理HTTP摘要身份驗證,我有兩個文本框,一個是名稱,另一個是密碼,當用戶使用正確的名稱和密碼登錄時,一個標籤將顯示auth和userid響應字符串。任何人都可以提供使用asiHttpRequest的HTTP摘要身份驗證
我想用asiHttpRequest來處理HTTP摘要身份驗證,我有兩個文本框,一個是名稱,另一個是密碼,當用戶使用正確的名稱和密碼登錄時,一個標籤將顯示auth和userid響應字符串。任何人都可以提供使用asiHttpRequest的HTTP摘要身份驗證
下面是如何將請求發送到谷歌進行身份驗證的示例代碼。你可以改變它來消化。希望能幫助到你。
NSString *username = @"[email protected]";
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];
編輯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];
u能解釋如何改變呢?感謝 – kevin
請參閱上面的編輯直接摘要認證。它是最簡單的一個。我之前沒有通過twangoo.com的身份驗證..抱歉不能有更多的幫助。 – Hadi