0

I'm actually building my application and using an API for multiple usage purpose and so using Alamofire, I'm working locally ATM but I can't get it to work.

(I have my local nodejs server https correctly running when I hit the API with the browser it's working all fine)

I've generated my own certificate and registered it in the Keychain but when I hit my local URL with a request I get the "code: 1200" from Xcode. But when I hit https://httpbin.org/get it's working all good.

(This is all tested with an Xcode Simulator)

What am I doing wrong?

AtulParmar
  • 4,358
  • 1
  • 24
  • 45
bornZaim
  • 13
  • 2
  • Is the IP you are using, same as that of your machine ? – Nitish May 07 '19 at 09:29
  • Im using a virtual host with MAMP PRO which is for test purpose only to "mimic" a real domain "api.myname.com" so when I hit the server (hosted at port 443) with a request the url is "https://api.myname.com/user -> GET" – bornZaim May 07 '19 at 09:32

2 Answers2

1

You can pin your certificate or disable certificate evaluation

Use this code for disable evaluation for your localhost:

 private static var Manager : Alamofire.SessionManager = {
        // Create the server trust policies
        let serverTrustPolicies: [String: ServerTrustPolicy] = [
            "your localhost": .disableEvaluation
        ]
        // Create custom manager
        let configuration = URLSessionConfiguration.default
        configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
        let man = Alamofire.SessionManager(
            configuration: URLSessionConfiguration.default,
            serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
        )
        return man
    }()

and this link could be helpful for pinning certificates

Hamed
  • 1,678
  • 18
  • 30
0

I finally get it to works for local development with the answer of a previous thread, this was basically related to the simulator note the certificate since this was working on web and postman:

https://stackoverflow.com/a/43877084

Thanks for your answer all, have a good one!

bornZaim
  • 13
  • 2