Objective-C iOS NSURLConnection statusCode 400 No body returned

1.4k views Asked by At

not really sure where to start here other then to dive into CF (I REALLY don't want to do that) but....

I have an NSURLConnection signing OAuth2 requests to an ASP.NET WebAPI Resource Server, this resource server returns JSON body AND statusCode 400. I have yet to find a way to parse the data from the response when it returns code 400.

Does anyone here have any ideas? I would prefer to keep using NSURLConnection as this is only an OAuth2 consumer class. My other code is using restkit, but I do not want the OAuth2 end to require said library.

3

There are 3 answers

1
Holyprin On

Interestingly enough, MVC4 ActionResult is broken in the RTM. Switching it over to Pure WebApi and fine tuning the response, I was able to finesse it into returning the proper data, it was likely serializing the json improperly which other languages weren't catching.

3
jatoben On

The process to parse data from a request which returns status 400 should be identical to that of a request returning status 200.

Simply note the status code in -connection:didReceiveResponse: and allow the request to continue; you will receive any additional data that the server sends in -connection:didReceiveData: as usual. Finally, you'll get a -connectionDidFinishLoading: call when all data has been received, and you can parse the JSON there.

1
David On

Does your HTTP request Accept header specify "application/json"? If so, then this is probably an IIS bug and not iOS.