我試圖讓一個小型的twitter客戶端運行,並在測試需要身份驗證的API調用時遇到問題。iPhone上的基本HTTP身份驗證
我的密碼裏有特殊字符,所以當我嘗試使用下面的代碼時它不起作用。
NSString *post = [NSString stringWithFormat:@"status=%@", [status stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@@%@/statuses/update.json", username, password, TwitterHostname]];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
我開始關注base64並將身份驗證放入標頭。我在他的base64實現中發現了Dave Dribin's的帖子,這似乎是有道理的。但是,當我嘗試使用它時,編譯器開始抱怨它無法找到openssl庫。所以我讀了我需要鏈接到libcrypto庫,但似乎並不存在iphone。
我也讀過一些人說蘋果不會允許使用加密庫的應用程序,這對我來說沒有任何意義。
所以現在我有點卡住和困惑。在我的應用程序中獲得基本身份驗證的最簡單方法是什麼?
乾杯
我改變了sendSynchronous調用initWithRequest:要求委託:自我和然後在委託中設置didReceiveAuthenticationChallenge,但沒有任何被調用。我嘗試了其他NSURLConnection委託方法,他們也沒有工作。有任何想法嗎? – Meroon 2009-06-14 22:09:35