Say I want to get the HTML of
http://www.google.com
as a String using some built-in classes of the Cocoa Touch framework.
What is the least amount of code I need to write?
I’ve gotten this far, but can’t figure out how to progress. There must be an easier way.
CFHTTPMessageRef req; NSURL *url = [NSURL URLWithString:@'http://www.google.com']; req = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR('GET'), (CFURLRef)url, kCFHTTPVersion1_1);
The quickest way is to use NSString’s
+stringWithContentsOfURL:method. However, this is a modal call, and your application will be non-responsive while it runs. You can either move it to a background thread, or use the NSURLConnection class to make a proper, asynchronous request.