Sptibo
Sptibo

Reputation: 283

response.result.value in alamofire post method is nil

        let parametersDictionary = [
        "email" : "[email protected]",
        "password" : "password"
    ]
    Alamofire.request("http://nanosoftech.com/store/user_check", method: .post, parameters: (parametersDictionary as NSDictionary) as? Parameters , encoding: JSONEncoding.default, headers: nil).responseJSON { response in
        print("response:", response.result.value)
    }

I'm working in post method api and above code is not working. I'm getting nil response. But this url is working properly in postman and android studio too. What is the reason behind this issue?

Upvotes: 3

Views: 2855

Answers (2)

Fangming
Fangming

Reputation: 25261

Your url only works when requesting using form with url encoded

enter image description here

Try to use this, as documented on GitHub

Alamofire.request("http://nanosoftech.com/store/user_check", method: .post, parameters: parametersDictionary , encoding: URLEncoding.default)

If this encoding doesn't work, try encoding: URLEncoding.httpBody

Upvotes: 2

Enamul Haque
Enamul Haque

Reputation: 5053

Just write look Like bellow.. It is working for me

Alamofire.request("http://era.com.bd/UserSignInSV", method: .post,parameters:["uname":txtUserId.text!,"pass":txtPassword.text!]).responseJSON{(responseData) -> Void in
        if((responseData.result.value != nil)){

            let jsonData = JSON(responseData.result.value)

        }
    }

Upvotes: 0

Related Questions