tags:

views:

18

answers:

1

Hello everyone

My problem is the following...

I read about sending http requests and receiving their responses on iPhone SDK 3.2 using NSURLRequest and NSHTTPURLResponse (All my requests are "get" and there's no "post") but I don't know how to do that exactly cause some of my responses are just strings (plain text) and some others are binary files (gzip and mp3)

Thank you in advance for the help

A: 

Hello, To perform a Http request, I use ASIHttpRequest:

NSURL *url = [NSURL URLWithString:my_url];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"GET"];
[request startSynchronous];

That works perfectly. Still need to figure out if it's fine with mp3 / zip files.

Luc

Luc
OK and how do you get the response please? let's say it's just a plain text...
You get the response with: NSData *response_data = [request responseData];To get the error: [request error];The example I show you above is for synchronous request, which is not the best sometime. I am using the asynchronous version of ASIHttpRequest now (just need to issue a [request startAsynchronous]) and implement the requestFinished and requestFailed in your delegate.
Luc