b1onic
b1onic

Reputation: 239

Downloading webpage source code with NSUrl

I'm porting a bash script in obj-c. Currently in the bash script I do 'curl http://... > file.txt' to download and save the webpage source code.

I played around with NSUrl, but I didn't get it to work. Any ideas ?

Upvotes: 0

Views: 226

Answers (2)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

Are you looking for something like this –

NSData *data = [NSData dataWithContentsOfURL:yourURL];
[data writeToFile:filePath atomically:YES];

Note that this is a synchronous method so it will block until data is downloaded.

Upvotes: 1

Jackelope11
Jackelope11

Reputation: 1171

If you are asking how to use NSUrl, just use the initWithString: method and put in your url with the @"string" format.

Upvotes: 0

Related Questions