0

I've been retrieving documents from a public web server by going to the URL and parsing the HTML tree with TFHpple, like this:

NSData *documentsHTMLData = [NSData dataWithContentsOfURL:myURL];
TFHpple *documentsParser = [TFHpple hppleWithHTMLData:documentsHTMLData];
....
....

The server is now being password protected and I was hoping to still be able to access it, perhaps using MKNetworkKit. I've got as far as:

MKNetworkEngine *myEngine = [[MKNetworkEngine alloc] init];
MKNetworkOperation *user = [myEngine operationWithURLString:myURL];
[user setUsername:@"test" password:@"test"];
[myEngine enqueueOperation:user];

but have no idea where to go from there with MKNetworkKit regarding how to then get access to directory structure.

I was hoping someone here might be able to point me in the right direction. Any ideas greatly appreciated.

Robert
  • 5,278
  • 43
  • 65
  • 115

1 Answers1

2

If your server is password protected, you need to know the authentication scheme used. If your server uses HTTP Basic/Digest authentication, your code above should just work. If your server serves you a HTML page and asks you to type a username/password (aka, HTTP+HTML Form based authentication) you are out of luck, unless you reverse engineer and find a workaround.

Mugunth
  • 14,461
  • 15
  • 66
  • 94
  • @Munguth: Thanks for the reply. I believe it uses HTTP basic authentication, in so far as encoding the url as `http://user:password@myURL` allows access. I think the code above works OK but I'm confused as to how to get visibility of directory. I tried simply putting the first code snippet after the second but that didn't work. – Robert Nov 19 '12 at 09:31
  • 1
    Try using the method [user addCompletionHandler:errorHandler:] and get the response string from the completion handler. The response string will be the HTML from where you should parse the data. The url should *NOT* contain user:password. MKNetworkKit does this internally. – Mugunth Nov 19 '12 at 09:37