2012-11-21 33 views
1

的是我的代碼NSURLConnection的不調用連接:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:

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]; 

我不明白爲什麼會發生這種情況?

+1

@EdwinIskandar我遇到同樣的問題,但我肯定使用HTTP POST(帶文件上傳)。你知道NSURLConnection需要滿足什麼其他期望來調用'didSendBodyData'方法嗎? –

回答

2

didSendBodyData僅在請求的主體包含POST請求中的消息數據時才被調用。你很可能正在執行GET。

從蘋果文檔:

連接:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:請求的 發送作爲主體(消息數據)被髮送(例如在 HTTP POST請求)。

+0

你確定。感謝回覆。 –

-1

這是因爲它在定義NSURLConnectionDataDelegate和你設置NSURLConnection的 代表。

+0

我已經在使用NSURLConnectionDataDelegate –

相關問題