1

这是我的代码

theDownloadConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

它正在调用这些 NSURLConnection 委托方法

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;

但它没有调用

- (void)connection:(NSURLConnection *)connection   didSendBodyData:(NSInteger)bytesWritten
                                                 totalBytesWritten:(NSInteger)totalBytesWritten
                                         totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

当我这样做时,NSURLConnection 委托调用的这个方法

[NSURLConnection connectionWithRequest:request delegate:self];

我不明白为什么会这样?

4

2 回答 2

2

didSendBodyData 仅在请求具有包含消息数据的正文时调用,例如 POST 请求。您很可能正在执行 GET。

来自苹果文档:

connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:作为请求的主体(消息数据)发送(例如在 http POST 请求中)。

于 2012-11-21T12:03:31.350 回答
-1

那是因为它在NSURLConnectionDataDelegate中定义并且您正在设置NSURLConnection 委托。

于 2012-11-21T12:14:34.943 回答