在iPhone SDK中,您如何以编程方式访问受.htaccess或访问控制保护的受密码保护的站点.
使用NSURLRequest,您可以从URL发出GET请求.但是,如果URL受到保护,您将如何发送用户名密码对.此外,如果使用标准MD5加密进行加密,该怎么办?
将这样的内容添加到HTTPConnectionDelegate:
-(void)connection:(NSURLConnection *)aConnection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if ([challenge previousFailureCount] == 0) { NSURLCredential *newCredential; newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone]; [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; } else { [[challenge sender] cancelAuthenticationChallenge:challenge]; } }