Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alamofire request always fails with "The request timed out" if Socket.io is connected

if socket.io is connected Alamofire is not working as expected, always getting req time out error. Alamofire works if i disable Socket.io

this is the error i'm getting

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." 
UserInfo={NSUnderlyingError=0x60800044c720 
{Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" 
UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}},
NSErrorFailingURLStringKey=https://enpoint.json, NSErrorFailingURLKey=https://enpoint.json, 
_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}

and this

_tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled

kind of similar issue reported on git https://github.com/Alamofire/Alamofire/issues/1545 but no answers.

I don't know what i'm doing wrong! Any help would be appreciated

like image 922
name-it Avatar asked May 03 '17 13:05

name-it


1 Answers

I was able to fix this issue by changing alamofire parameter encoding. By default Alamofire sets encoding to URLEncoding if you are not passing any encoding argument. Use URLEncoding for GET and DELETE request. Use JSONEncoding.default for all other requests (API should have support for this).

Still i'm not sure why it was working w/o socket and wasn't working with socket on.

like image 148
name-it Avatar answered Nov 15 '22 19:11

name-it