查找URL的下载大小(内容长度) [英] finding the download size of a URL (Content-Length)
本文介绍了查找URL的下载大小(内容长度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一些Objective-C代码来查询URL并提供下载大小,类似于此示例:
I'm looking for some objective-c code to query a URL and give the download size, similar to this example: Checking Download size before download
但是在Objective-c中,并且使用ASIHttp是可以的.
but in objective-c, and using ASIHttp is OK.
推荐答案
发起HTTP HEAD请求:
Initiate the HTTP HEAD request:
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSMutableURLRequest *httpRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[httpRequest setHTTPMethod:@"HEAD"];
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:httpRequest delegate:self];
执行委托:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse {
long long filesize = [aResponse expectedContentLength];
}
这篇关于查找URL的下载大小(内容长度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文