我正在使用 Apple 文档中的代码进行一些 HTTP 通信。我可以成功连接到 URL,但我无法从我的服务器接收数据。
// 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
NSMutableData *receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
原因可能是:
我
receivedData
在 Action 本身中声明。注释说我应该在别处声明它。我应该在哪里申报?我应该将其声明为控制器的财产吗?如何
[[NSMutableData data] retain]
找到 URL 之外的 URLif{}
?