你好,我需要創建一個progressView,當我從我的web服務加載數據。response expectedContentLength return -1
實際上expectedContentLength總是返回-1。
看了很多相似的問題後,它看起來像我的web服務永遠不會發送Content-Length :.
然後我請與捲曲,這裏是結果:
< HTTP/1.1 200 OK
< Date: Thu, 21 Jun 2012 10:04:39 GMT
< Server: Apache/2.2.16 (Debian)
< X-Powered-By: PHP/5.3.3-7+squeeze9
< cache-control: no-cache
< Vary: Accept-Encoding
< Content-Type: text/html; charset=UTF-8
< Content-Length: 3239
< Connection: Keep-Alive
< Set-Cookie: PHPSESSID=u4o4i9dofdgnkfmtnf163635j6; path=/
,這裏是我的代碼來捕獲長
long long expectDataSize;
long long currentDataSize;
....
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
{
NSLog(@"expect content length %lld", [response expectedContentLength]);
expectDataSize = [response expectedContentLength];
currentDataSize = 0;
}
任何人都已經看這個問題?
嘗試:'的NSLog(@ 「%@」,[響應allHeaderFields]);'看如果響應對象實際上具有「Content Length」標題字段。 – Alladinian
這裏的代碼示例http://stackoverflow.com/questions/23585432/totalbytesexpectedtowrite-is-1-in-nsurlsessiondownloadtask/33372970#33372970 –