我正在使用 Apple Document 创建一个应用程序。我成功连接到服务器,但我从服务器收到 0 个字节(没有响应数据)。我采取以下步骤:
我创建了一个基于视图的应用程序并添加了一个属性“receivedData”:
在 ViewController.h 中:
@property (nonatomic, retain) NSMutableData *receivedData;
在 ViewController.m 中:
@synthesize receivedData;
ViewController.m 的动作 'ViewDidLoad',我补充说:
receivedData = [NSMutableData alloc];
在视图中添加一个按钮并为其添加操作:
// create the request NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://..."] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { // Create the NSMutableData that will hold // the received data // receivedData is declared as a method instance elsewhere receivedData=[[NSMutableData data] retain]; } else { // inform the user that the download could not be made }
当我调试这些代码时,我发现 receivedData 返回 0 个字节。关于出了什么问题的任何想法?对我的代码进行简单修改将不胜感激。