2013-02-02 53 views
0

我試圖從googletrends下載文件。爲了做到這一點,我必須登錄。我使用NSURLConnection,所以我認爲我必須使用登錄谷歌下載文件 - ios

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 

我必須設置什麼參數?即如何定義用戶名和密碼?

回答

2

使用NSURLCredential傳遞的用戶名和密碼:

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{ 
    NSURLCredential *credential = [NSURLCredential credentialWithUser:userName password:userPassword persistence:NSURLCredentialPersistenceForSession]; 

    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; 
} 

請查看本教程:Handling URL Authentication challenges

+0

嗨THX這是偉大的(想如果我可以投票了) - 谷歌不需要登錄,所以我可能必須找到一種方法來確保連接被認證 – iEatPenguinsForBreakfast

+0

@ user2034977:高興:)感謝您的評論 –