这些类中的“response”指的是协议响应(HTTP报头等),而不是内容。
要获取内容,您有几个选项:
-
在异步模式下使用NSURLConnection:
Using NSURLConnection
-
// Error checks omitted
NSURL *URL = [NSURL URLwithString:@"http://www.myserver.com/myservice.php?param=foobar"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil
error:nil];
-
使用
[NSString stringWithContentsOfURL:]
NSURL *URL = [NSURL URLwithString:@"http://www.myserver.com/myservice.php?param=foobar"];
NSString *content = [NSString stringWithContentsOfURL:URL];
当然,您应该使用选项2和3
您的内容将非常小的大小,以保持响应能力。