Is there an Objective-C equivalent to Python urllib and urllib2?

Are there any equivalents in objective-c to the following python urllib2 functions?

Request, urlopen, HTTPError, HTTPCookieProRequest, urlopen, HTTPError, HTTPCookieProcessor

Also, how would I able to to this and change the method from "get" to "post"?

Answers


NSMutableHTTPURLRequest, a category of NSMutableURLRequest, is how you set up an HTTP request. Using that class you will specify a method (GET or POST), headers and a url.

NSURLConnection is how you open the connection. You will pass in a request and delegate, and the delegate will receive data, errors and messages related to the connection as they become available.

NSHTTPCookieStorage is how you manage existing cookies. There are a number of related classes in the NSHTTPCookie family.

With urlopen, you open a connection and read from it. There is no direct equivalent to that unless you use something lower level like CFReadStreamCreateForHTTPRequest. In Objective-C everything is passive, where you are notified when events occur on the stream.


You're looking for some combination of NSURL, NSURLRequest, NSURLConnection, NSHTTPConnection, etc. Check out the URL Loading System Programming Guide for all the information you need.


A previous similar question.

ASIHTTPRequest is a good library.


Need Your Help

Using System.out in Osgi?

osgi apache-felix bndtools

I am using bndtools and trying to get a "Hello World" running.