从Web服务器检索文件大小

编程入门 行业动态 更新时间:2024-10-24 12:26:37
本文介绍了从Web服务器检索文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

本文发布于:2023-11-01 12:02:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件大小   服务器   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!