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

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

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

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

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

實(shí)際上,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=/

這是我捕捉長(zhǎng)度的代碼

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)看到這個(gè)問題了嗎?

Anyone have already see this problem ?

推薦答案

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

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

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

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

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

But when i use NSurlConnection

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

響應(yīng)將用Gzip"壓縮(不要問我為什么).如果響應(yīng)是用 Gzip 編碼的,則不可能知道長(zhǎng)度,然后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].

如果你真的想獲得長(zhǎng)度,你可以簡(jiǎn)單地強(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)容長(zhǎng)度返回 -1的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Can#39;t change target membership visibility in Xcode 4.5(無(wú)法更改 Xcode 4.5 中的目標(biāo)成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動(dòng)態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級(jí)到 Xcode 4.5 后,iOS 5 SDK 消失了)
Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中從 CIImage 創(chuàng)建 UIImage 時(shí)遇到問題)
Open target=quot;_blankquot; links outside of UIWebView in Safari(打開目標(biāo)=“_blank;Safari 中 UIWebView 之外的鏈接)
主站蜘蛛池模板: 中文字幕精品一区二区三区精品 | 成人午夜精品一区二区三区 | 91精品久久久久久久久99蜜臂 | 国产免费一区二区 | 国产精品久久久久久久久免费 | 日韩亚洲一区二区 | 青娱乐自拍 | 亚洲视频一区二区三区四区 | 国产免费一区二区 | 日本成年免费网站 | 欧美日韩国产一区二区 | 91精品在线播放 | 在线国产一区二区 | 久久小视频 | 久综合 | 成人在线观看亚洲 | 男女羞羞视频在线 | 在线观看国产视频 | 久久国产欧美一区二区三区精品 | 91私密视频 | 最新中文字幕在线 | 国产三级在线观看播放 | 91精品久久久久久久久中文字幕 | 成人精品在线观看 | 久久久久久毛片免费观看 | 三级黄色片在线 | 亚洲国产欧美国产综合一区 | 午夜无码国产理论在线 | 国产成人精品一区二三区在线观看 | 精品一二三 | 岛国在线免费观看 | 神马久久香蕉 | 精品视频一区二区在线观看 | 狠狠影院 | 精品一区久久 | 北条麻妃一区二区三区在线观看 | 久久久久久久久久久久久9999 | 国产午夜精品视频 | 亚洲风情在线观看 | 人操人人 | 久草资源在线 |