2011-02-11 155 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]/