久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

響應(yīng)預(yù)期內(nèi)容長度返回 -1

response expectedContentLength return -1(響應(yīng)預(yù)期內(nèi)容長度返回 -1)
本文介紹了響應(yīng)預(yù)期內(nèi)容長度返回 -1的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

您好,當(dāng)我從 Web 服務(wù)加載數(shù)據(jù)時,我需要創(chuàng)建一個 progressView.

Hello i need to create a progressView when i load data from my webservice.

實際上,expectedContentLength 總是返回 -1.

Actually the expectedContentLength alway return -1.

看了很多類似的問題后,看起來我的網(wǎng)絡(luò)服務(wù)從未發(fā)送過 Content-Length:.

After look lots of similary problem it looks like my webservice never send the Content-Length:.

然后我用 CURL 檢查,結(jié)果如下:

Then i check with CURL and here is the result :

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

有人已經(jīng)看到這個問題了嗎?

Anyone have already see this problem ?

推薦答案

好的,我自己解決了,這是我真正的問題和解決方案:

Ok i've fix it myself here is my real problem and a solution :

當(dāng)我用 Curl 詢問時,我可以得到長度沒問題.

When i ask with Curl i can get the length no problem.

但是當(dāng)我使用 NSurlConnection 時

But when i use NSurlConnection

NSURLConnection *c = [[NSURLConnection alloc] initWithRequest:req delegate:self];

響應(yīng)將用Gzip"壓縮(不要問我為什么).如果響應(yīng)是用 Gzip 編碼的,則不可能知道長度,然后expectedContentLength"返回-1.[response allHeaderFields] 中沒有Content-Length".

The response will be compress with "Gzip" (don't ask me why). And if the response is encode with Gzip it's impossible to know the length, then "expectedContentLength" return -1. And "Content-Length" is absent from [response allHeaderFields].

如果你真的想獲得長度,你可以簡單地強(qiáng)制不要像這樣使用 Gzip:

If you really want to get the length you can simply force to not use Gzip like this :

[req setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];

這篇關(guān)于響應(yīng)預(yù)期內(nèi)容長度返回 -1的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標(biāo)成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中從 CIImage 創(chuàng)建 UIImage 時遇到問題)
Open target=quot;_blankquot; links outside of UIWebView in Safari(打開目標(biāo)=“_blank;Safari 中 UIWebView 之外的鏈接)
主站蜘蛛池模板: 亚洲精品欧美一区二区三区 | 久久日韩粉嫩一区二区三区 | 午夜精品在线观看 | 欧美一区精品 | 日日摸夜夜添夜夜添精品视频 | 精品久久国产 | 日日日色 | 综合精品| a级片www| 日韩手机在线看片 | 精品真实国产乱文在线 | 国产免费福利小视频 | 国产黄色精品在线观看 | 国产女人与拘做视频免费 | 免费看av大片 | 国产成人福利在线观看 | 亚洲精品18| 久草视频在线播放 | 亚洲国产精品成人久久久 | 欧美一区2区三区4区公司二百 | 国产精品视频播放 | 日日爽 | 三级在线免费 | 欧美一级视频在线观看 | 欧美在线国产精品 | 亚洲精品区 | 成人中文字幕在线观看 | 亚洲精品91| 免费激情网站 | 久久黄色| 羞视频在线观看 | 精品亚洲一区二区 | 激情六月丁香 | 一区二区三区视频 | 91久久精品一区二区二区 | 免费成人高清 | 另类视频在线 | 国产成人99久久亚洲综合精品 | 欧美在线网站 | 欧美成人一区二区三区片免费 | 国产精品一区二区久久精品爱微奶 |