I have a server running in node, I tried using postman and it works just fine, but when I execute it from IOS client, it doesn't execute the URL, I checked my server it doesn't even called the API
Node server
router.post('/api/accounts/login', (req, res, next) => {
var user = new User():
user.name = req.body.name;
user.pass = req.body.password;
user.save((err) => {
res.json("Success");
});
});
let mainURL = "https://examplelogin.com"
let facebookLogin = "\(mainURL)/api/accounts/login"
func loginButtonTapped(_ name: String, _ pass: String) {
let parameters: [String: AnyObject] = [
"name": name as AnyObject,
"password": pass as AnyObject
]
Alamofire.request(facebookLogin, method: .post, parameters: parameters, encoding: JSONEncoding.default)
.responseJSON { response in
if let value = response.result.value {
let json = JSON(value)
// Do something
}
}
}
try this
1.add this code for show error.
else if let ERROR = response.result.error {
print(ERROR.localizedDescription)
}
2.Add this code in info.plist file.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key> <true/>
</dict>