任何人都可以粘贴一些代码如何做一个简单的http get in cocoa?
干得好!
这个从网络服务器抓取一个图像.
NSURL *url = [ NSURL URLWithString: [ NSString stringWithFormat:@"http://www.somewebsite.com/demo.png"] ]; image = [ [ UIImage alloc ] initWithData: [ NSData dataWithContentsOfURL: url ] ];
或者,这个抓住一个网页......
NSURL *url = [ NSURL URLWithString:[ NSString stringWithFormat: @"http://www.google.com/search?q=%@", query ] ]; NSURLRequest *request = [ NSURLRequest requestWithURL: url ];
要异步执行,您应该检查NSURLConnection.