views:

28

answers:

2

Hi,

I'm currently using Webkit to display a mobile web on my iPhone app.
The domain is password 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,
Tee

A: 

i think you need to pass the username and password in the css and js includes also...

mklfarha
A: 

This 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];
Robot K
FYI, missing a ';' at the end of your NSURLCrendentialStorage call.
Wayne Hartman
Also missing a '@' in your initWithHost parameter. :)
Wayne Hartman
Thanks. I've fixred them both.
Robot K