How to pass a CPF as a parameter of type NSDictionary for a call with JSON and POST?

0

Hello, I have a question. I need to pass a user-entered CPF as a parameter in my POST call to return with his data. The call works with an already registered CPF, but only works if the CPF is passed directly as a parameter, as I did below and type NSDictionary . How to pass the user-entered CPF as a parameter in the call? Here's the part of my code where I call:

let mutableURLRequest = NSMutableURLRequest(URL: URL)

mutableURLRequest.HTTPMethod = "POST"

let cpfPesquisa = cpf

let parameters: NSDictionary = ["cpf":"098.748.876-32"]

do {
    mutableURLRequest.HTTPBody = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions())
    mutableURLRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
    mutableURLRequest.addValue("application/json", forHTTPHeaderField: "Accept")

The constant parameters is passed to get the data from this CPF, but I want it to be the user-entered ( cpfPesquisa ), instead of this default CPF, how can I do this? Thanks for your help.

    
asked by anonymous 11.11.2015 / 03:44

1 answer

2

Try changing this:

let parameters: NSDictionary = ["cpf":"098.748.876-32"]

So:

let parameters: NSDictionary = ["cpf":cpfPesquisa]

Or, as suggested by iTSangar in a comment, so:

let parameters: ["cpf":cpfPesquisa]
    
11.11.2015 / 04:04