Question

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 ?

Était-ce utile?

La solution

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 friend NSMutableURLRequest).

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).

Autres conseils

CFUrlRef is toll free bridged with NSURL *: you can use them interchangeably. In general the cfnetwork stuff is lower level than the NSURLRequest stuff - only drop down to it if you need to.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top