Tag Archives: code -1001

Error domain = nsurlerrordomain code = – 1001 “request timeout occurred in swift alamofire get request. ” UserInfo={NSUnderlyingErro

ErrorDomain =NSURLErrorDomain Code=-1001 “request timeout.” UserInfo={NSUnderlyingError=0x1c0a48310 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 “(null)” UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}
For this reason, I have checked for a long time. There are many posts setting timeout on the Internet. However, this GET request returns this error without timeout. Here is an introduction to encoding usage scenarios
JSONEncoding. Default is placed in HttpBody, such as post requests
2. URLEncoding. Default is concatenated address in GET, such as GET request
3. URLEncoding(destination:. MethodDependent) is a custom URLEncoding. If the value of methodDependent is in GET, HEAD, and DELETE, it will be concatenated. The other methods are in the httpBody.
4. URLEncoding(destination:.httpbody) is placed in httpBody
So I replaced the previous JSONEncoding. Default with URLEncoding. Default
Alamofire.request(url, method: .get, parameters: nil, encoding:JSONEncoding.default, headers: [“Content-Type”:”application/json”]).responseJSON { (response) in
}
Alamofire.request(url, method: .get, parameters: nil, encoding:URLEncoding.default, headers: [“Content-Type”:”application/json”]).responseJSON { (response) in
}