假设我想获取
的HTMLhttp://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);
最佳答案
最快的方法是使用 NSString 的 +stringWithContentsOfURL:
方法。但是,这是一个模态调用,您的应用程序在运行时将没有响应。您可以将其移至后台线程,或使用 NSURLConnection 类发出适当的异步请求。
关于iphone - 使用 Cocoa/iPhoneSDK 获取 URL 的字符串内容的最快方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/241860/