Objective C - Webkit external files causing 401
I'm currently using Webkit to display a mobile web on my iPhone app.
The domain is passwo开发者_如何学编程rd protected, so I pass the username & password to the request.It loads the main HTML page fine, however, even after passing the username & password, any other pages that the main HTML page loads (i.e css and js) are all returning 401.
Is there a way around that?
Thanks,
TeeThis is one of the use cases for ASIWebPageRequest.
If you want something lower level, you'll have to create an NSURLCredential instance and an NSURLProtectionSpace and save them to the credential store. At this point, the UIWebView should use the credential for all requests that match the protection space (which basically represents your site).
Here's some sample code, taken from here, which is not really where I'd expect to find it.
NSURLCredential *credential = [[NSURLCredential alloc]
initWithUser: @"userName"
password: @"password"
persistence: NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: @"www.mydomain.com"
port: 80
protocol: @"http"
realm: @"mydomain.com"
authenticationMethod: NSURLAuthenticationMethodDefault];
[[NSURLCredentialStorage sharedCredentialStorage]
setDefaultCredential: credential
forProtectionSpace: protectionSpace];
[credential release];
[protectionSpace release];
i think you need to pass the username and password in the css and js includes also...
精彩评论