api / api/placesを呼び出してサーバーhttp://sand.comへの接続を確立する必要があります。上記のURLとAuthorizationヘッダーにNSMutableURLRequestオブジェクトを使用しました。数回接続が確立されましたが、データを受信しませんでしたが、接続がまったく確立されておらず、代わりにdidReceiveAuthenticationChallengeが複数回呼び出されています。(Authorizationヘッダーの設定値はbase64形式のusername:passwordです)どこが間違っていますか?
NSString *urlString =
[NSString stringWithFormat:@"http://sand.com/api/places",hostURL];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:300.0];
[theRequest setValue:@"Basic c3VyYWJoaV9taXNocmE6bWlzaHJhaml2ZQ==" forHTTPHeaderField:@"Authorization"];
[theRequest setHTTPMethod:@"GET"];
NSURLconnections *nuc = [NSURLconnections new];
nuc.delegate = self;
[nuc connectToRequest:theRequest];
- (void)connectToRequest:(NSURLRequest*)theRequest
{
urlConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (urlConnection)
{
responseData=[NSMutableData data];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0)
{
NikeAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
username = appDelegate.username; password = appDelegate.password;
NSURLCredential *cred = [[NSURLCredential alloc]
initWithUser:username
password:password
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
}
}