How to integrate with PagSeguro using UIWebView in Swift

1

I'm trying to integrate PagSeguro with my Swift application using UIWebView using POST method, but it did not work. follows error that is being returned and the part of my code where I make the call:

NSError domain error: "NSCocoaErrorDomain" - code: 3840 0x79741210

    let URL = NSURL(string: "https://ws.pagseguro.uol.com.br/v2/checkout/")

    let mutableURLRequest = NSMutableURLRequest(URL: URL!)

    mutableURLRequest.HTTPMethod = "POST"

    let parameters = ["email":"[email protected] ",
        "token":"PUB9DC3C03DD97D4FB4AB1EE70161FE3063",
        "itemId1":"0001",
        "itemDescription1":"Notebook Prata",
        "itemAmount1":"24300.00",
        "itemQuantity1":"1",
        "itemWeight1":"1000"]

    do {

        mutableURLRequest.HTTPBody = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions())

        mutableURLRequest.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
        mutableURLRequest.addValue("charset=ISO-8859-1", forHTTPHeaderField: "Content-Type")

        let config = NSURLSessionConfiguration.defaultSessionConfiguration()

        let session = NSURLSession(configuration: config)

        let task = session.dataTaskWithRequest(mutableURLRequest, completionHandler: {

            (data, response, error) in

            guard let responseData = data else {

                print("Error: did not receive data")

                return

            }

            guard error == nil else {

                print("error calling POST on /posts/1")

                print(error)

                return

            }

            let post: NSDictionary

            do {

                post = try NSJSONSerialization.JSONObjectWithData(responseData, options: []) as! NSDictionary

            }

            catch {

                print("error parsing response from POST on /posts")

                return

            }

            print("resultado: ")

            print(post)

        })

        task.resume()

    }

    catch {

        print("Error parsing response from POST on /posts")

        return

    }
    
asked by anonymous 17.11.2015 / 04:33

0 answers