开发者

JSON GET Method request

开发者 https://www.devze.com 2023-02-10 03:03 出处:网络
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 function

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

精彩评论

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