letsCode
letsCode

Reputation: 3046

AlamoFire isn't sending the params to PHP

Here is my AlamoFire code

let parameters = ["test": "true"]

Alamofire.request(urlString, method: .post, parameters: parameters ,encoding: JSONEncoding.default, headers: nil).responseJSON {
response in
  switch response.result {
                case .success:
                    print(response)
                    break
                case .failure(let error):

                    print(error)
                }
}

An example of my PHP code is here. I always get the error. Is it my PHP or AlamoFire?

if($_POST['test'] == 'true'){
    $json = json_encode(array(
        "ack" => "success",
        "message" => "good"
    ));
      echo $json;
} else {
    $json = json_encode(array(
        "ack" => "error",
        "message" => "not good"
    ));
      echo $json;
}

Upvotes: 0

Views: 30

Answers (1)

Ragen Dazs
Ragen Dazs

Reputation: 2170

Try change your encoding for URLEncoding.default

AF.request(url, method: .post, parameters: p, encoding: URLEncoding.default).responseJSON {

Upvotes: 1

Related Questions