How can i download the html content of a webpage given an url? using objective c..
+1
A:
Depends on what you are trying to do. For a web view:
webView = [[UIWebview alloc] loadRequest:(NSURLRequest *)request];
mahboudz
2010-02-25 04:11:16
+3
A:
Assuming it's on iPhone or Mac OS X, use the sample here:
Linking CURL with Objective C might be possible, but why?
Seva Alekseyev
2010-02-25 04:25:39
+2
A:
Use stringWithContentsOfURL:usedEncoding:error:
from NSString
NSURL * url = ... some url
NSError * error;
NSStringEncoding * encoding;
NSString * htmlContent = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error];
Brandon Bodnár
2010-02-25 04:31:30
While this will work, you should never do this from the main thread as it will block until the call returns, which may be a long time if there are network issues. You should either do this on a separate thread or use the asynchronous methods of `NSURLConnection` instead.
Rob Keniger
2010-02-25 05:05:30
correct, that you should not do this in the main thread, but with how easy Operation Queues are to use, it would make more sense to use them as opposed to redoing what NSString already does if you want all the contents of the URL. A good tutorial for Operation Queues is at http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/
Brandon Bodnár
2010-02-25 05:26:12