I'm using Alamofire for a https connection.
However when testing in Alamofire I get this error:
URLError occurred: URLError(_nsError: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://192.168.X.XX/VMSSite/Handlers/Common/iOSServer.ashx?RegID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://192.168.X.XX/VMSSite/Handlers/Common/iOSServer.ashx?RegID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}) status code: nil
My source looks like this:
var defaultManager = Alamofire.SessionManager.default
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"192.168.X.XX:443": .disableEvaluation,
"192.168.X.XX": .disableEvaluation
]
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30 //seconds
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
//defaultManager = SessionManager(configuration: configuration, delegate: SessionDelegate(), serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))
defaultManager = SessionManager(configuration: configuration, serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))
defaultManager.request("https://192.168.X.XX/VMSSite/Handlers/Common/iOSServer.ashx?RegID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", method: .post, parameters: nil, encoding: JSONEncoding.default).responseJSON { response in
debugPrint(response)
var statusCode = response.response?.statusCode
if let error = response.result.error as? AFError {
statusCode = error._code // statusCode private
switch error {
case .invalidURL(let url):
print("Invalid URL: \(url) - \(error.localizedDescription)")
case .parameterEncodingFailed(let reason):
print("Parameter encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
case .multipartEncodingFailed(let reason):
print("Multipart encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
case .responseValidationFailed(let reason):
print("Response validation failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
switch reason {
case .dataFileNil, .dataFileReadFailed:
print("Downloaded file could not be read")
case .missingContentType(let acceptableContentTypes):
print("Content Type Missing: \(acceptableContentTypes)")
case .unacceptableContentType(let acceptableContentTypes, let responseContentType):
print("Response content type: \(responseContentType) was unacceptable: \(acceptableContentTypes)")
case .unacceptableStatusCode(let code):
print("Response status code was unacceptable: \(code)")
statusCode = code
}
case .responseSerializationFailed(let reason):
print("Response serialization failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
// statusCode = 3840 ???? maybe..
}
print("Underlying error: \(error.underlyingError)")
} else if let error = response.result.error as? URLError {
print("URLError occurred: \(error)")
} else {
print("Unknown error: \(response.result.error)")
}
print("status code: \(statusCode)") // the status code
}
}
I'm using Swift 3 and Alamofire 4.0 from the xcode8.1 branch. Please help me.
And
How to set value for Exception Domains in ATS for dynamic hostnames?
Note: If i am using bypassURLAuthentication with this code its working fine with https. but as per post here bypassURLAuthentication is not recommended to use for PRODUCTION. so i need help to solve this issue.