I use Alamofire to fulfill all network requests in my application. I ran into a problem when setting the encoding as JSON in the get request.
Following in my request:
Alamofire.request(url, method: .get, parameters: params, encoding: JSONEncoding.default) .responseJSON(completionHandler: { (response) in switch response.result { case .success(let retrivedResult): print(retrivedResult) // success(brandTags) break case .failure(let errorGiven): print(errorGiven) print(String(data: response.data!, encoding: String.Encoding.utf8) ?? "") failure(APICaller.parseErrorAndGiveMessage(givenError: errorGiven as NSError)) break } })
When I encode the parameters as JSONEncoding.default
as above, the request always disconnects with the following in my logs:
2016-12-27 12:22:41.425948 xyz[5140:133008] [] nw_endpoint_flow_service_writes [2.1 35.164.98.40:80 ready socket-flow (satisfied)] Write request has 4294967295 frame count, 0 byte count 2016-12-27 12:23:41.485534 xyz[5140:133041] [] nw_endpoint_flow_service_writes [2.1 35.164.98.40:80 ready socket-flow (satisfied)] Write request has 4294967295 frame count, 0 byte count Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x60000024a9b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=http:
But when I delete the parameter encoding as shown below, the request completes correctly without any problems.
Alamofire.request(url, method: .get, parameters: params, encoding: JSONEncoding.default) .responseJSON(completionHandler: { (response) in switch response.result { case .success(let retrivedResult): print(retrivedResult) // success(brandTags) break case .failure(let errorGiven): print(errorGiven) print(String(data: response.data!, encoding: String.Encoding.utf8) ?? "") failure(APICaller.parseErrorAndGiveMessage(givenError: errorGiven as NSError)) break } })
What is the difference?
UPDATE:
I discovered this problem with the Alamofire community on Github and this is their answer . Hope this helps people facing this issue.
source share