views:

34

answers:

1

How would I get returningResponse (into say, a NSString) from the following code:

NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

I think I can get the info that I need into a string but I can't call anything on response because it's null. Therefore, I assume that I need to call something on result. The problem is, I don't know what to call.

(The URL request has been coded prior to the code sample. I know that that works.) I want to be able to detect if the request as successful.

+1  A: 

According to the documentation for the URL loading system:

If NSURLConnection is unable to download the URL the method will return nil and any available NSError instance by-reference in the appropriate parameter.

So, see what's in your "error" parameter to find out what the problem is.

David Gelhar
@David - How so? Code please? (Yes, I'm being lazy, but isn't that natural to being a programmer?)
Moshe
See the NSError class reference. Or, on the simplest level, just NSLog it: NSLog(@"%@", error);
David Gelhar
Thanks. Silly me, I didnt realize that the error value was being passed by (erm, reference, or value? I'm not very good with those terms... )
Moshe
David Gelhar
- Thanks a ton.
Moshe