0
votes

I'm using ASIHttpRequest, on iOS, to upload a file. In some cases, the user can't upload the file (because some conditions aren't fulfilled), so my server needs to return an error (400 status code) with a custom header. When it's happen, the ASIHttpRequest fails but with no status code and response headers ...

But it's only for large data (more than 1M). For smaller data, it's work. I've digged in the source and find that when the server returns 400 before all data were sent, CFNetwork returns a kCFStreamEventErrorOccurred and from here, it's impossible to read other thing than the error in the read stream. But if the request failed after all data were sent, it send a kCFStreamEventEndEncountered and from here, status code and response readers can be read.

As ASIHttpRequest is discontinued, I would like to fix it myself but I haven't find how to do it. I fear that it's a CFNetwork limitation ... I've find nothing about that on the internet or the documentation ...

Does anyone know how to handle that ? Or know enough about CFNetwork to give me some leads ?

Thanks !

1

1 Answers

0
votes

Ok, I've found the answer.

I've fixed it on the server side. If it returns an error WITH a body (even only one character) it works on the iOS side, CFNetwork is able to read the status code and the headers.

I use Tomcat with Spring on the server and it's may be a bug when you only set the status code in the reponse. Maybe it doesn't close the response stream correctly, I don't know.

CFNetwork seems to be very sensible by the way ... Because it work with no body with NSUrlRequest.