【发布时间】:2009-02-27 04:03:38
【问题描述】:
我正在使用 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。注释说我应该在别处声明它。我应该在哪里申报?我应该将其声明为控制器的财产吗?[[NSMutableData data] retain]如何找到位于if{}之外的 URL?
【问题讨论】:
-
Tom Harrington 已经掌握了所有技术细节,但如果您想了解他所描述的实际工作情况,take a look at the GitHub source to either my demo/training iPhone application 或 ones by coders much more advanced than I am such as the Git-Phone app. 这两个示例应用程序都可以准确拨打您的电话以身作则,以身作则往往是最好的方法。
标签: iphone http connection nsurlconnection communication