且构网

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

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

更新时间:2023-12-03 10:47:16

我正在使用与 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