3
        let parametersDictionary = [
        "email" : "name@gmail.com",
        "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?

Sptibo
  • 281
  • 2
  • 8
  • 22

2 Answers2

2

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

Fangming
  • 24,551
  • 6
  • 100
  • 90
  • @Sptibo Just noticed that you are sending an http call, not https one. You will need to do https only or your app will be rejected by app store. From the beginning of 2017, http calls are only allowed in a `UIWebView` – Fangming Jul 06 '17 at 17:16
  • @Sptibo I just tried to send post request with `{"email" : "name@email.com", "password": "haha"}` and got nil respond – Fangming Jul 06 '17 at 17:19
  • But i've been working with http urls in get methods and are working well. If I test this code with another http url and post some form data then that is working. But this url is giving me nil response. – Sptibo Jul 06 '17 at 17:20
  • @Sptibo Look at the screen shot I updated. Your url is indeed returning nil – Fangming Jul 06 '17 at 17:23
  • You've send raw data. But I'd send form data. Is that same thing? Try sending form data and look at the response. – Sptibo Jul 06 '17 at 17:29
  • @Sptibo Updated my answer – Fangming Jul 06 '17 at 17:36
  • Thank you @Fangming Ning. Yesterday I didn't marked your changes. URLEncoding.default is working. – Sptibo Jul 07 '17 at 02:21
  • I see the image now (from home), so it must have been something like that. Sorry for the false alarm! I'll delete my comments now :) – stkent Aug 08 '18 at 23:01
0

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)

        }
    }
Enamul Haque
  • 4,789
  • 1
  • 37
  • 50
  • it is working in live project running on. I think you should see the json response..Can you show me json response... – Enamul Haque Jul 06 '17 at 17:48
  • 1
    Check browser using get because browser do not response from post: http://nanosoftech.com/store/user_check?email=name@gmail.com&password=password – Enamul Haque Jul 06 '17 at 17:50
  • I've tested this url in postman, checked form-data and fill "email" and "password" in body and send it. Its working well in postman. – Sptibo Jul 07 '17 at 02:02
  • Hello dear, I have found json response my json response is from the code I have printed in xcode with same code. Is json is look like bellow. If still feel problem please share your code...:::jsonData : { "loginNodes" : [ { "errorCode" : "1", "errorMessage" : "Unauthorized User ID. Sign In Denied." } ] } – Enamul Haque Jul 07 '17 at 10:45