2011-02-11 139 views
0

我开发了一个需要通过HTTP身份验证请求标头发送用户名和密码的iphone应用程序。任何人都可以引导我或发送该功能的源代码。JSON GET方法请求

回答

0

您需要实施NSURLConnection:didReceiveAuthenticationChallenge:方法。

- (void)request:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
    if ([challenge previousFailureCount] == 0) { 
     NSURLCredential *newCredential = [NSURLCredential 
               credentialWithUser:@"username" 
               password:@"password" 
               persistence:NSURLCredentialPersistenceNone]; 
     [[challenge sender] useCredential:newCredential 
       forAuthenticationChallenge:challenge]; 
    } 
    else { 
     [[challenge sender] cancelAuthenticationChallenge:challenge]; 
    } 
} 

编辑:或者你可以简单地发送的URL的凭证格式http://username:[email protected]/