views:

48

answers:

3

I am looking for a Cocoa class that will enable me to load a web page (html source) from a given URL. To make things a bit more complicated I need to be able to set user name and password for this contention since the access to web page is restricted.

+5  A: 

NSURLConnection supports the behavior you describe. See the section on handling authentication challenges.

Alex
+3  A: 

If it's basic authentication you can just put the username and password in the URL like so:

NSURLRequest *request =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://username:[email protected]"]];

[NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
Chris McCall
+1  A: 

I tend to use Ben Copsey's ASIHTTPRequest library, which works fine both on OSX and the iPhone. I know most of the stuff it does can be done with NSURLReqest, but this one just makes life so much easier.

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/top_secret/"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setUsername:@"username"];
[request setPassword:@"password"];
rage