0

On a button press action, I'm trying to invoke a logout request to a server. Here is the action code:

@IBAction func buttonpress(_ sender: UIButton) {

    Alamofire.request("https://securelogin.pu.ac.in/cgi-bin/login?cmd=logout").responseString { response in
        debugPrint(response)

        print(response.request)
        print(response.response)
        print(response.data)
        print(response.result)

        if let JSON = response.result.value {
            print("JSON \(JSON)")
        }
    }
}

But the response of this request always fails with the following error:

[Request]: GET httpbin.org/get [Response]: nil [Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x1742425e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=httpbin.org/get, NSErrorFailingURLKey=httpbin.org/get, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.} Optional(0 bytes) FAILURE

Can you please point me out what might cause this failure?

x4h1d
  • 6,042
  • 1
  • 31
  • 46
hammad119
  • 1
  • 1
  • 3
    what error you are getting? For any post api's should pass some parameters. You are not passing anything here. Check your api documentation – Anil Varghese Feb 18 '17 at 14:44
  • You need to call web service with post method and with parameters like userid or access token – Maulik Pandya Feb 18 '17 at 16:22
  • Alamofire.request(.GET, "https://securelogin.pu.ac.in/cgi-bin/login?cmd=logout/get", parameters: nil, encoding: .URL).responseString(completionHandler: { (request: NSURLRequest, response: HTTPURLResponse?, responseBody: String?, error: NSError?) -> Void in – hammad119 Feb 18 '17 at 16:46
  • tried this too,, but it shows extra argument in call – hammad119 Feb 18 '17 at 16:46
  • [Request]: GET http://httpbin.org/get [Response]: nil [Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x1742425e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://httpbin.org/get, NSErrorFailingURLKey=http://httpbin.org/get, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.} Optional(0 bytes) FAILURE – hammad119 Feb 18 '17 at 17:38
  • this is what i am getting as error – hammad119 Feb 18 '17 at 17:38
  • ADD ATS in info.plist – Vinodh Feb 19 '17 at 03:28
  • Investigate your error log. – x4h1d Feb 22 '17 at 09:18

0 Answers0