Object C - External Webkit Files Invoking 401

I am currently using Webkit to display a mobile web application on my iPhone application.
The domain is password protected, so I pass in the username and password for the request.

It loads the main HTML page in order, however, even after passing the username and password, all other pages loaded with the main HTML page (e.g. css and js) will return 401.

Is there any way around this?

Thanks,
Tee

0
source share
2 answers

This is one use case for ASIWebPageRequest .

If you need a lower level, you need to create an instance of NSURLCredential and NSURLProtectionSpace and store them in the credential storage. At this point, UIWebView should use the credentials for all requests matching the security space (which basically represents your site).


Here is an example of code taken from here that is actually not where I would 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]; 
0
source

I think you need to pass username and password to css, and js also includes ...

0
source

Source: https://habr.com/ru/post/943721/


All Articles