从Web服务器检索文件大小 [英] Retrieve file size from web server
问题描述
寻找使用可可/基础从Web服务器检索文件大小的方法。我知道可以使用NSURLconnection将返回包含文件大小的NSURLResponse。有没有任何其他方式来获取尺寸。我正在寻找一个同步的方式做,所以当我做[myClass getsize]大小被返回。
Looking for a way to retrieve a file size from a web server using cocoa/foundation. I know one can use NSURLconnection which will return NSURLResponse that contains the file size. Is there any other way to get the size. I'm looking for a synchronous way of doing it so when i do [myClass getsize] the size is returned.
感谢
推荐答案
您可以使用 NSMutableURLRequest
发送HTTP HEAD请求方法 setHTTPMethod
)。您将获得与GET相同的响应标头,但是您不必下载整个资源正文。如果您要同步获取数据,请使用 > 方法 / apple_ref / occ / clm / NSURLConnection / sendSynchronousRequest:returningResponse:error:rel =nofollow noreferrer NSURLConnection 。
You can use a NSMutableURLRequest
to send a HTTP HEAD request (there’s a method called setHTTPMethod
). You’ll get the same response headers as with GET, but you won’t have to download the whole resource body. And if you want to get the data synchronously, use the sendSynchronousRequest…
method of NSURLConnection
.
这篇关于从Web服务器检索文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!