Question: Alamofire Parameter missing in response

Question

Alamofire Parameter missing in response

Answers 1
Added at 2016-12-21 06:12
Tags
Question

I install pod file of Alamofire for calling web service and successfully retrieve data when there is no parameter pass to web service but when I try to pass parameter It shows this parameter missing.

Here is my code:

let parameters: Parameters = ["client_id": "1","user_token":"A4YkkH5FdTbRCI8Mk98s"]
let url = "http://***********/index.php/Web_api/get_client_profile"
Alamofire.request(url , method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in

            switch(response.result) {
            case .success(_):
                if response.result.value != nil{
                    print(response.result.value)
                }
                break

            case .failure(_):
                print(response.result.error)
                break

            }
        }

RESPONSE:

{
      "message : client_id parameter missing",
      "Code : 500"
}

What I am doing wrong ? Please help me with it.
Thank you

Answers
nr: #1 dodano: 2016-12-21 06:12

After banging my head for like 6 Hours I figured a different approach, here is a way of calling it, which works:

var request: Alamofire.Request? {
    didSet {
        oldValue?.cancel()
    }
}

func loadDataFromServer(message:String?) {
    // Prerequisites for Connection to Server
    let timeParameter =  self.getLastTimeStamp()
    let url = "http://your.amazing.url/path/component/classs"
    let parameter = ["timestamp":timeParameter]

    //sho hud only of there is no data listed
    if message != nil {
        HUD.show(HUDContentType.label("Loading.."))
    }

    self.request = Alamofire.request(url, method: .post, parameters:parameter)
    if let request = request as? DataRequest {
        request.responseString { response in
            PKHUD.sharedHUD.hide()
            do{
                let dictionary = try JSONSerialization.jsonObject(with: response.data!, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary

                //Save and Fetch
                self.saveTimestamp(dictionary: dictionary, wsEntity: "Section")
                self.saveDataInPersisanceStorage(articalDictionary: dictionary)
                self.fetchDatafromCore()

                //HUD.flash(.success, delay:1.0)
            }catch{
                //HUD.flash(.error, delay:1.0)
            }
        }
    }
}
Source Show
◀ Wstecz