AFNetworking requestWithMethod:URLString: parameters:error: returns nil for URLString

I was creating a request as below to test one of my network calls.

NSMutableURLRequest *request = [self.requestSerializer
URLString:[NSURL URLWithString:URLString relativeToURL:self.baseURL].absoluteString

Annoyingly the requestSerializer would return nil for the URLString. This is the url I was expecting it to return.
{baseURL}/users/396250/bookings/33050/cancellation?reason=Bad weather

After a lot of search around for why requestSerialiser was failing on query strings, I realised I actually needed to escape the space. As soon as I did this, it worked fine.

This did reveal a bit of an architectural issue with my app and the testing as the request made within the app worked without any problems, which would suggest that at a higher level my requests are being escaped but the tests don’t seem to route through there.

Leave a Comment