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 written in Objective-C and works in both Mac OS X and iPhone applications.
It is suitable performing basic HTTP requests and interacting with REST-based services (GET / POST / PUT / DELETE). The included ASIFormDataRequest subclass makes it easy to submit POST data and files using multipart/form-data.

Here is an sample code on how easy is to make a http-post from objective c.

    ASIFormDataRequest  *request =
         [[[ASIFormDataRequest  alloc]  initWithURL:url] autorelease];
    [request setPostValue:@"Ben" forKey:@"first_name"];
    [request setPostValue:@"Copsey" forKey:@"last_name"];
    [request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];


How to install and use ASIHTTPRequest?

1) Add the files

  • Copy the files you need to your project folder, and add them to your Xcode project. An overview of the ASIHTTPRequest source files appears here.

2) Link against CFNetwork, SystemConfiguration and zlib

  • Choose Project -> Edit Active Target from the menu.
  • Click the plus button in the bottom left of the window.
  • Choose “CFNetwork.framework” from the list, and click Add.
  • Repeat the same operation for “SystemConfiguration.framework” and “libz.1.2.3.dylib”

What’s next?

How to: Show Alerts on iPhone
How to: Read iPhone Preferences From Application
How to: Cache Image on iPhone

Leave a Reply

five + 3 =