开发者

JSON GET Method request

I have developed a iphone 开发者_运维百科application that need to send User name and Password through HTTP authentication request header. can any one guide me or sent the source code for that functionalities.


You'll need to implement the NSURLConnection:didReceiveAuthenticationChallenge: method.

- (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];
    } 
}

Edit: Or you could simply send the credentials in the URL in the format http://username:password@www.example.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜