CFUrl 和 NSUrl 有什么区别
我想向 Objective-C 中的 Web 服务器发送一个简单的 HTTP。 据我所知,最常见的方法是将 NSURLRequest 与 NSUrl 一起使用...... 但我也偶然发现了 CFNetwork 库,它也可用于与 Web 服务器通信。所以我的问题是:这两种方法有什么区别,我应该使用哪一种?
I would like to send a simple HTTP to a web server in Objective-C.
From what i've seen, the most common way is to use the NSURLRequest with NSUrl....
But i have also stumbled upon the CFNetwork Library which can also be used to communicate with web servers. So my question is : what is the difference between the 2 methods and which one should i use ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CFNetwork 是一个较低级别的基于 C 的库,而
NSURL
和朋友是较高级别的 Foundation 框架的一部分。Foundation 应该满足您通过 HTTP 与 Web 服务器通信的所有需求。值得注意的类有
NSURL
、NURLConnection
、NSURLRequest
(它是可变的朋友NSMutableURLRequest
)。您应该能够构建复杂的请求,包括使用 Foundation 对象的多部分表单请求,而不必深入到 CFNetwork 库。
当您开始考虑创建和管理自己的套接字和流时,CFNetwork 非常有用(尽管 Foundation 也可以做到这一点)。
CFNetwork is a lower-level C-based library, whereas
NSURL
and friends are part of the higher level Foundation framework.Foundation should cater to all your needs for communicating with web servers via HTTP. Notable classes to look at are
NSURL
,NURLConnection
,NSURLRequest
(and it's mutable friendNSMutableURLRequest
).You should be able to build up complex requests, including things like multi-part form requests using Foundation objects and not having to go down into the CFNetwork library.
CFNetwork is useful for when you start to look at creating and managing your own sockets and streams (although, Foundation can do this too).
CFUrlRef
是与NSURL *
桥接的免费电话:您可以互换使用它们。一般来说,cfnetwork 的东西比NSURLRequest
的东西级别低 - 只有在需要时才下拉到它。CFUrlRef
is toll free bridged withNSURL *
: you can use them interchangeably. In general the cfnetwork stuff is lower level than theNSURLRequest
stuff - only drop down to it if you need to.