nithin
nithin

Reputation: 2457

ios - Swift JSON Post request

I'm new in swift language.This is my JSON which needs to be send to server for user login

data={"email":"test@***.com","password":"mypassword","service":"login","deviceid":"sasa","devicetype":"android"}

I tried these codes

    let params = [
            "data": [
                "email": username,
                "password": password,
                "service": "login",
                "deviceid": "sasa",
                "devicetype": "android"
            ]
        ]
Alamofire.request(.POST, "http://***.com/login", parameters: params, encoding: .JSON)
            .responseJSON {  response in
                print(response)
                        }

but the response from server

SUCCESS: {
    service = login;
    status = failure;
    statusmessage = "Failure in post request , please check the key for form data";
}

Upvotes: 0

Views: 203

Answers (1)

Hamza Ansari
Hamza Ansari

Reputation: 3084

Use encoding type URL instead of JSON:

Alamofire.request(.POST, "http://***.com/login", parameters: params, encoding: .URL)
            .responseJSON {  response in
                print(response)
                        }

Upvotes: 1

Related Questions