我正在尝试运行一个小型 Twitter 客户端,但在测试需要身份验证的 API 调用时遇到了问题。
我的密码中有特殊字符,所以当我尝试使用以下代码时它不起作用。
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 的帖子,这似乎是有道理的。但是,当我尝试使用它时,编译器开始抱怨它如何找不到 openssl 库。所以我读到我需要链接到 libcrypto 库,但它似乎不存在于 iphone 中。
我还读到有人说苹果不允许使用加密库的应用程序,这对我来说没有意义。
所以现在我有点卡住和困惑。在我的应用程序中获得基本身份验证的最简单方法是什么?
干杯