cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
242
Views
2
Helpful
2
Replies
Highlighted
Beginner

try to access cmx server with swift (ios)

I use Alamofire (Alamofire is an HTTP networking library written in Swift.)  to send rest API to server which includes basic auth  ( username & pass)

this code comes from

GitHub - Alamofire/Alamofire: Elegant HTTP Networking in Swift


let user = "user"

let password = "password"

Alamofire.request("10.34.250.12/api/location/v2/clients/count")

  .authenticate(user: user, password: password)

  .responseJSON { response in

   debugPrint(response)

  }

but it keeps respond me this "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “10.34.250.12” which could put your confidential information at risk."

Everyone's tags (3)
2 REPLIES 2
Frequent Contributor

Re: try to access cmx server with swift (ios)

Hi,

I am not sure if this will help but Chrome Postman has the ability to create code snippets from HTTP requests such as your GET /api/location/v2/clients/count into various languages.  Postman has swift (NSURL) translater which produces the code.

Let us know if that works,

Matt



import Foundation

let headers = [

  "authorization": "Basic bGVhcm5pbmc6bGVhcm5pbmc=",

  "cache-control": "no-cache",

  "postman-token": "586ea267-e976-60ce-ab5b-1ab81617b07b"

]

let request = NSMutableURLRequest(url: NSURL(string: "https://cmxlocationsandbox.cisco.com/api/location/v2/clients/count")! as URL,

                                        cachePolicy: .useProtocolCachePolicy,

                                    timeoutInterval: 10.0)

request.httpMethod = "GET"

request.allHTTPHeaderFields = headers

let session = URLSession.shared

let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in

  if (error != nil) {

    print(error)

  } else {

    let httpResponse = response as? HTTPURLResponse

    print(httpResponse)

  }

})

dataTask.resume()

Frequent Contributor

Re: try to access cmx server with swift (ios)

CreatePlease to create content
Content for Community-Ad
August's Community Spotlight Awards