1

I am working on iOS application and facing one strange issue. I am using AFNetworking framework to communicate with server (HTTPS communication). I am retrieving student data from server by using "getStudentData" web service API. It is post request. It works for all user ids except one. It fails when we have a data for more than 450 students. Below are the error details,

Error Domain=NSURLErrorDomain Code=-1017 "cannot parse response" UserInfo=0x7bf9c7d0 {NSErrorFailingURLStringKey=https://www.fdmobileservices.com/mAccountsWeb/services/speedpass/rpc, _kCFStreamErrorCodeKey=-1, NSErrorFailingURLKey=https://www.fdmobileservices.com/mAccountsWeb/services/speedpass/rpc, NSLocalizedDescription=cannot parse response, _kCFStreamErrorDomainKey=4,    NSUnderlyingError=0x7bf9a380 "cannot parse response"}

As per error description, It tells "Could Not parse", so I think it may be due to server is returning "nil" or some data other than JSON format.

But I am not able to trace it since from application side it directly goes into below method,

 - (void)connection:(NSURLConnection __unused *)connection
didFailWithError:(NSError *)error

Is there any way from application side to trace root cause? This method works for other user login except one.

I tried using web client to access this service by same user login, it works well and return data of 450 students. I think due to some reason iOS network layer rejects this. I am trying to find out.

Thanks in advance.

Swapnil
  • 1,858
  • 2
  • 22
  • 49

1 Answers1

0

As you can see here, kCFURLErrorCannotParseResponse = -1017. So probably this is saying that there is something wrong in the parameters.

If You're using AFNetworking 2.0, I suggest You to deep debug your response flow with severals breakpoints. Specifically try to set a breakpoint on AFURLResponseSerialization.m at the start of the method:

- (id)responseObjectForResponse:(NSURLResponse *)response
                           data:(NSData *)data
                          error:(NSError *__autoreleasing *)error;

Inside the method, if the below condition is true, probably there is something wrong (but you can step into validateResponse:data:error: to better understand what's wrong):

   if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error])

If the above condition is false you can then check about the generated responseString:

NSString *responseString = [[NSString alloc] initWithData:data encoding:stringEncoding];

If you're expecting json data, check that responseString is not nil and data data is valid, maybe also the stringEncoding.
Also ensure that the contentType that you're receiving is the one you're expecting.

Mat
  • 7,613
  • 4
  • 40
  • 56
  • Yes I tried to debug "responseObjectForResponse:" method, but It doesn't come into this method, instead goes to "didfailwithError:" .... – Swapnil Oct 23 '15 at 13:18