且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS中的NSURLConnection和基本HTTP身份验证

更新时间:2023-12-03 10:52:04

我正在使用与 MGTwitterEngine 并设置 NSMutableURLRequest theRequest )如下:

I'm using an asynchronous connection with MGTwitterEngine and it sets the authorization in the NSMutableURLRequest (theRequest) like so:

NSString *authStr = [NSString stringWithFormat:@"%@:%@", [self username], [self password]];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];
[theRequest setValue:authValue forHTTPHeaderField:@"Authorization"];

我不相信这种方法需要通过挑战循环,但我可能错了

I don't believe this method requires going through the challenge loop but I could be wrong