How to call a web service in swift2 Xcode 7

0

I have already tried 1000 and 1 thing and still could not find a way to call my web service and get the results you want.

Can someone tell me the best way to connect to my web service and call my methods in swift2 with xcode 7?

    
asked by anonymous 02.02.2016 / 22:55

1 answer

0

Using the Alamofire library I made the request as follows:

    let URL = NSURL(string: "https://****.*****.com/*****.svc/rest/GetByID")!
    let mutableURLRequest = NSMutableURLRequest(URL: URL)
    mutableURLRequest.HTTPMethod = "POST"

    let parameters = ["ID": "23"]

    do {
        mutableURLRequest.HTTPBody = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions())
    } catch {
    }

    mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")

    Alamofire.request(mutableURLRequest)
        .responseJSON{
            response in
            if let JSON = response.result.value{

                let dataSelected = [JSON.valueForKey("Price")!]         //Quando vem apenas um objecto
                print("RESULTADO \(dataSelected)")
            }
    }
    
11.02.2016 / 16:14