Reputation: 2217
I am developing an iOS app with Swift3
and using Alamofire
as network library.But it gives responseValidationFailed
error with Status Code: 401
on HTTP
request. API
and other configurations are correct but it gives error. Here is my network call -
//Register user
private func registerUser() -> Void {
Alamofire.request(
URL(string: "my_url")!,
method: .post,
parameters: ["email": email!, "gender": gender, "age":"20" ,"password": password!])
.validate(statusCode: 200..<300)
.responseJSON { (response) -> Void in
print(self.CLASS_NAME+" -- registerUser() -- response -- "+response.debugDescription)
}
}
}
Here is my debugDescription
-
RegistrationViewController -- registerUser() -- response -- [Request]: POST http://beta.thesmartclubapp.com:3000/api/register/other/
[Response]: <NSHTTPURLResponse: 0x60000022f100> { URL: http://beta.thesmartclubapp.com:3000/api/register/other/ } { Status Code: 401, Headers {
Connection = (
"keep-alive"
);
"Content-Length" = (
118
);
"Content-Type" = (
"application/json; charset=utf-8"
);
Date = (
"Tue, 02 Jan 2018 08:22:25 GMT"
);
Etag = (
"W/\"76-3KZXMvbalkbJsfbjY65r3dx/Mak\""
);
"Strict-Transport-Security" = (
"max-age=15552000; includeSubDomains"
);
Vary = (
Origin
);
"X-Content-Type-Options" = (
nosniff
);
"X-DNS-Prefetch-Control" = (
off
);
"X-Download-Options" = (
noopen
);
"X-Frame-Options" = (
SAMEORIGIN
);
"X-XSS-Protection" = (
"1; mode=block"
);
} }
[Data]: 118 bytes
[Result]: FAILURE: responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(401))
[Timeline]: Timeline: { "Request Start Time": 536574145.442, "Initial Response Time": 536574146.054, "Request Completed Time": 536574146.310, "Serialization Completed Time": 536574146.310, "Latency": 0.613 secs, "Request Duration": 0.868 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.868 secs }
I searched on Google and Stackoverflow . Other solutions did not work for me. Any help will be appreciated.
Upvotes: 0
Views: 8198
Reputation: 6648
You need to give a name(and confirm password also, check all the rules set by service), because service needs that. See the result gotten by postman.
The updated old answer : remove .validate(statusCode: 200..<300)
is part of true reason, 😂
Upvotes: 2