0

ダウンロードする前に画像のサイズを取得しようとすると問題が発生します。

Xcode でリモート サーバーから画像ファイルのヘッダーを読み取ろうとしています。サンプル画像へのリンクはこちら: http://www.iseivijosdaile.lt/iPadWS/images/thumbnail_1195165011LIDF-0130.png

端末コマンド

curl --head http://www.iseivijosdaile.lt/iPadWS/images/thumbnail_1195165011LIDF-0130.png

Content-Length を返します: 125803

次の

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
    if ([response respondsToSelector:@selector(allHeaderFields)]) {
        NSDictionary *dictionary = [httpResponse allHeaderFields];
        NSLog([dictionary description]);
    }
}

フィールド Content-Length が含まれていません。

なぜこれが起こっているのですか、どうすればこれを解決できますか?

ありがとう!

4

1 に答える 1

4

これは、 a の Content-LengthNSURLResponse *が残りのヘッダー フィールドと一緒に保存されず、独自のフィールドに保存されるためです。

[httpResponse expectedContentLength];
于 2012-01-16T20:40:56.747 に答える