totalBytesExpectedToWrite is -1 in NSURLSessionDownloadTask

后端 未结 3 1043
情深已故
情深已故 2021-01-12 12:34

I faced with a strange problem. I load file from the Internet using NSURLSession and NSURLSessionDownloadTask. Here is the code

NSU         


        
3条回答
  •  忘掉有多难
    2021-01-12 13:12

    -1 is NSURLSessionTransferSizeUnknown, which means that the http server did not provide a "Content-Length" header (and the data is sent using "Transfer-Encoding: chunked").

    There is probably not much that you can do. You could try if the workaround from https://stackoverflow.com/a/12599242/1187415 works in your case as well:

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:anURL];
    [request addValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
    

提交回复
热议问题