Perseus
Perseus

Reputation: 1588

API for Http Request/Response in iPhone

In the iPhone application whether all the network operations are done ONLY using the NSURLConnections?? I am using the NSURLConnections and its delegate methods ConnectiondidReceiveResponse,ConnectiondidFinishLoading,etc to download the files.

My question is whether NSURLConnection API available only in cocoa-touch for the Http request/reponse ? Is there any other API available ??

Can we use the NSURLConnection for uploading the files also ??

I guess there are many questions , but I am really confused. Please help me out !

Upvotes: 1

Views: 215

Answers (2)

Nenad M
Nenad M

Reputation: 3055

You can also try the MKNetworkKit framework: MKNetworkKit

Easy to use and works really fine!

Upvotes: 0

Feel Physics
Feel Physics

Reputation: 2783

I feel difficulty to upload file with NSURLConnection, too. Finally, I use AFNetworking Library. It works very well.

NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
    [formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}];

AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
[operation start];

You can find the library page at below address.

https://github.com/AFNetworking/AFNetworking

In addition, there is CocoaPods which manage libraries of objective-C. I'm trying to use it.

https://github.com/CocoaPods/CocoaPods/

Upvotes: 1

Related Questions