我使用新的iOS 5方法發出異步url請求:sendAsynchronousRequest:queue:completionHandler :.這使用塊來處理響應,但是沒有調用NSURLConnectionDelegate委託方法?我看不到在此實例中設置NSUrlConnection類的委託的方法?使用sendAsynchronousRequest處理401響應:queue:completionHandler:
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"HTTP response code: %i", httpResponse.statusCode);
if (error != nil) {
NSLog(@"There was error with the synchronous request: %@", error.description);
}
}];
我之所以需要委託方法是因爲我的電話的人得到一個401響應,iOS系統處理以不同的方式 - 推遲認證委託方法。當401響應返回時 - httpResponse.statusCode只是「0」。
有沒有辦法阻止iOS試圖處理401不同?特別是,我想我需要使用continueWithoutCredentialForAuthenticationChallenge:委託方法 - 但在這種情況下沒有委託被調用。
謝謝!
使用與代表,像initWithRequest的連接方式之一:代表: – 2012-04-03 04:30:01
看一看這個答案: http://stackoverflow.com/questions/12828060/authentication-with-nsurlconnection-sendasynchronousrequest-with-完成手 – 2013-07-29 12:34:23