I need to access some plist files from a remote server, which are in a password protected directory. In case of not using a password to access the directory, i use the simple code and it works:
NSString *query = @"http://www.sante.com/FFFF/privat/updateDates.plist";
NSURL *urlDates = [NSURL URLWithString:[query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSDictionary *datesUrl = [NSDictionary dictionaryWithContentsOfURL:urlDates];
But in case of password protected directory, does it exist a way to treat it in xcode (without using NSUrlCOnnection, xmlparser because i don't want to parse the file while i can access directly by using dictionaryWithContentsOfURL)?
Edit: The point is that i just want to write some code to access/download the plist files (which are in a password protected directory of server) from the webserver to ios device. But i don't know how to. In case of not using pa开发者_如何学编程ssword for accessing server directory, my above code works very well, but i need to access them in secured mode, and i just need to validate the webserver directory password programatically (hard coded).
If you need to deal with customising the download process by supporting authentication, then you need to stop using dictionaryWithContentsOfURL:
and start using NSConnection
because NSConnection
is the API for customising URL downloads. Particularly, look at the delegate method connection:didReceiveAuthenticationChallenge:
which is where you hook in to the authentication procedure.
You don't need to use an XML parser, because you have no need to parse the downloaded contents. Hand the data off to NSPropertyListSerialization
once you've downloaded them and that can return an NSDictionary
instance to you.
精彩评论