Bu sorudaki yayınlarda bulunan çeşitli fikirleri denemeden birçok saati harcadım. Kıvrımı kullanırken istenen üstbilgiyi alırım: İçerik Uzunluğu.NSURLSession, Content-Length (http üstbilgisi) sunucusundan nasıl döndürülür? Objective-c, ios
tuşu:: Vary:
- (void) trythis { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:myURL]; request.HTTPMethod = @"HEAD"; NSURLSessionDownloadTask *uploadTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL *url,NSURLResponse *response,NSError *error) { NSLog(@"handler size: %lld", response.expectedContentLength); NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; NSDictionary* headers = [httpResponse allHeaderFields]; NSArray *keys = [headers allKeys]; for(NSString *key in keys){ NSLog(@"key: %@ : %@", key, [headers valueForKey:key]); } NSLog(@""); }]; // 5 [uploadTask resume]; }
Bu başlıkları döndürür: Burada
(SO yere bulundu) benim son girişimi Accept-Encoding, User-Agent tuşu: Sunucu: Apache/2.4.12 tuşu: Bağlantı: Canlı tutma tuşu: Son Güncelleme: Cts, 13 Haziran 2015 23:03:46 GMT tuşu: Content-Type: ses/mpeg tuşu: Accept-Aralıkları: bayt anahtar: Tarih: Sal, 12 Nisan 2016 17:59:21 GMT tuşu: İçerik-Kodlama: gzip (macbook'da) curl alıyorum kullanma
:
bukle -I http://boulderhomegrown.com/fiddletunes/JerusalemRidge-100.mp3
HTTP/1.1 200 OK Tarih: Sal, 12 Nis 2016 14:55:17 GMT Sunucu: Apache/2.4.12 Son Değiştirilme: Cmt, 13 Jun 2015 23:03:46 GMT ETag: "2ec0bc0-1a172e -5186e3ca6b55f " Kabul Aralıkları: bayt İçerik-Uzunluk: 1709870 Vary: User-Agent Content-Type-Kodlama Kabul: ses/mpeg
NOT içerik-uzunluk !! Ve elbette, url her ikisinde de aynıdır. Hedefimdeki bir örnek değişkeni-c.
Kullandığınız "response.expectedContentLength" ile neyin yanlış olduğu? – jtbandes
Geri geldi -1. –
Curl komutunuzun bir GET isteği ve NSURLSession öğenizin bir HEAD isteği yaptığı anlaşılıyor. 'Request.HTTPMethod = @ "HEAD"; 'i kaldırırsanız ne olur? – EricS