寻找使用可可/基础从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服务器检索文件大小
发布评论