Sunday 9th Nov 2008

ASIHTTPRequest goes iPhone

It’s been a while since my last update, having been rather busy with my day job. Now that I have a bit of time to myself, I’m going to be doing a bit more work on ASIHTTPRequest.

I’ve just posted a gigantic update to the Github repository, get it while it’s hot:

http://github.com/pokeb/asi-http-request/tarball/master

Or via the magic of Git here:

$ git clone git://github.com/pokeb/asi-http-request.git

What’s new?

iPhone support

I know lots of people have been using ASIHTTPRequest on iPhone already, but there were quite a few kinks to iron out. Initial support for iPhone is now included, and there’s a sample app in the Xcode project. I haven’t tested all features yet (eg: Authentication + Keychains), so some bits may need more work.

Progress tracking has been re-written for compatibility with iPhone, as UIProgressViews have a different interface for setting progress from NSProgressIndicators. ASIHTTPRequest will automatically figure out which kind of progress indicator you’re trying to update, and manage the details for you.

ASINetworkQueue

This new NSOperationQueue subclass manages tracking the progress of multiple requests at once. Using this, you can show the progress of a set of requests using a single NSProgressIndicator (or UIProgressView on iPhone).

Refactoring - ASIFormDataRequest

I originally intended ASIHTTPRequest to be about making it easier to POST data to servers in the same way that multipart/form-data forms in HTML work. However, from the feedback I’ve received, a few people have been using it for sending data in other ways, for example SOAP requests or using REST, and populating the request body themselves.

I decided to split the ASIHTTPRequest class in two. The main ASIHTTPRequest class handles all the basic HTTP stuff - setting up the request, sending and receiving data, handling authentication and cookies. The new ASIFormDataRequest subclass handles multipart form POST requests.

What does this mean for your applications? If you want to manage the request body yourself, simply subclass ASIHTTPRequest and override main. If you want to POST form data and files, use an ASIFormDataRequest instead, and let it build your request body for you.

Memory behaviour

A fair number of memory leaks have been fixed (thanks, Clang Static Analyzer!), and the main loop for a particular request now cleans the autorelease pool every cycle so that a gigantic backlog doesn’t mount up in memory.

Lots more

You can now set the request method (GET / POST / PUT / DELETE) via the requestMethod property. Note that ASIHTTPRequest will override this if you use postData (or fileData with ASIFormDataRequest).

I’ve also added loads more Unit Tests, and fixed a fair number of bugs.

Free publicity for every reader

Finally, a thank you to everyone who has taken the time to write to me about ASIHTTPRequest over the last few months. I would very much like to compile a list of applications that use it to appear on this website. If you are using ASIHTTPRequest in a shipping Mac OS or iPhone app, and wouldn’t be adverse to some free publicity, please drop me an email!

Posted by Ben @ 2:12 PM

Saturday 13th Sep 2008

ASIHTTPRequest update: Cookies and Timeouts

ASIHTTPRequest now has cookie support, which should help people wanting to talk to servers that manage authentication with a session cookie. I’d originally rolled by own cookie support, before realising that Apple had done all this work for me with NSHTTPCookie and NSHTTPCookieStorage (DOH!). Just in case it’s useful to someone for something else, there’s a PHP port of my cookie header parsing code here.

I’ve also added the ability to configure timeouts for when requests take too long. No idea why it took me so long to realise this would be useful.

Posted by Ben @ 11:42 AM

Friday 1st Aug 2008

ASIHTTPRequest: New features, bug fixes and documentation

I've greatly improved ASIHTTPRequest over the last few weeks. Along with bug fixes, the latest version has session persistence for HTTP authentication and easy access to request and response headers.

To celebrate, I've even decided to write some documentation!

Posted by Ben @ 4:34 PM

Wednesday 16th Jul 2008

Clang! And the bugs are gone!

Tagged:

Picture of Barry Scott

The Clang Static Analyzer: I found and fixed around 20 Memex Trails memory leaks IN LESS THAN 10 MINUTES, including the time it took to download it and read the instructions!!

It also caught a few other miscellaneous bugs in Memex Trails, and I fixed a silly leak in the recently released ASIHTTPRequest. I really like their HTML reports. If you write any Cocoa stuff at all, you should stop what you're doing now and give it a try!

Via: DF

Posted by Ben @ 1:21 PM

Monday 14th Jul 2008

ASIHTTPRequest: An easy to use CFNetwork wrapper for HTTP requests

Apple provides two methods for sending data to / loading data from URLs in Cocoa applications. NSURLConnection, and the lower level CFNetwork API.

NSURLConnection is easy to use, but it provides no way to obtain information about upload progress - a pita if your application happens to involve uploading large files.

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier. It is suitable for when you want to submit data to an existing web form, or don't want to mess around with SOAP or XML-RPC.

It provides:

  • Ability for setting up progress delegates (e.g. NSProgressIndicators) to show information about download AND upload progress
  • An easy interface for adding POST data to requests
  • The ability to submit files on local drives as part of POST data, analogous to the HTML file input mechanism
  • Basic authentication (username and password) support
  • Integrated Keychain support
  • Based on NSOperation to make queuing requests and background operation easy

You can grab the latest source via git thusly:

$ git clone git://github.com/pokeb/asi-http-request.git

Or just get a tarbar here:

http://github.com/pokeb/asi-http-request/tarball/master

ASIHTTPRequest comes as part of a simple application that demonstrates many of the features above, just look at AppDelegate.m for good pointers on basic usage, or read the comments in ASIHTTPRequest.h for more detail.

ASIHTTPRequest is partly based on code from Apple's ImageClient code samples, so if it doesn't meet your needs, take a look at their CFNetwork examples for more.

ASIHTTPRequest is my first open source Objective-C code. I hope to expand the class and example application further (unit tests, maybe even iphone examples...) in the coming months. If you find it helpful, please do get in touch!

Posted by Ben @ 10:27 PM