I have a problem with Alamofire.
I have this old iOS app working with Swift 3 and Alamofire 4 and my POST Request isn't working. At first i though it was the API itself but the request works well on Android and Postman.
I'm sending on the body a Optional variable and a Content-Type on the header.
func getResponseFromURL(url : String,methodName : String,paramData : Dictionary<String, Any>? , block:@escaping voidRequestCompletionBlock)
{
self.dataBlock = block
let urlString:String = WebService.BASE_URL + url
print ("This is the body", paramData)
if (methodName == AlamofireHelper.POST_METHOD)
{
Alamofire.request(urlString, method: .post, parameters: paramData, encoding: URLEncoding.default, headers: ["Content-Type" : "application/json"])
.responseJSON
{
(response:DataResponse<Any>) in
print("Watch ExecutionTime of \(urlString) is \(response.timeline.description)")
if self.isRequestSuccess(response: response)
{
switch(response.result)
{
case .success(_):
if response.result.value != nil
{
self.dataBlock((response.result.value as? NSDictionary)!,nil)
}
break
case .failure(_):
if response.result.error != nil
{
let dictResponse:NSDictionary = NSDictionary.init()
self.dataBlock(dictResponse,response.result.error!)
}
break
}
}
else
{
let dictResponse:NSDictionary = NSDictionary.init()
self.dataBlock(dictResponse,response.result.error!)
}
}
}
I'm facing a timeout error. Also, i checked on the WebService and my request is never going to the API, so the Alamofire request isn't working at all.
Watch ExecutionTime of https://{url} is Timeline: { "Latency": 60.803 secs, "Request Duration": 60.803 secs, "Serialization Duration": 0.000 secs, "Total Duration": 60.803 secs } URLError occurred: URLError(_nsError: Error Domain=NSURLErrorDomain Code=-1001 "Se ha agotado el tiempo de espera." UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x2817a6580 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <4B692193-DE99-4AFF-8259-A711625C2F18>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <4B692193-DE99-4AFF-8259-A711625C2F18>.<1>"
What should i do?
Your simulator is probably not connected to the internet. Try relaunching it. If that doesn't work try:
OS Simulator -> Reset Content and Settings
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.