Reputation: 95
I am using Afnetwork 3. I am a new one for IOS development. I want to connect some API using POST method.
+(void)postExecuteWithParams:(NSString *)first secondParm:(NSDictionary *)inParams onCompletion:(JSONResponseBlock)completionBlock {
NSString *baseURL = @"xyz";
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:baseURL]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager POST:first parameters:inParams progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject)
{
NSLog(@"JSON: %@", responseObject);
completionBlock(responseObject);
//here is place for code executed in success case
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error: %@", [error localizedDescription]);
}];
}
When I use this code I am getting the error like this
Error: Request failed: internal server error (500)
can i know what is the reason for this error and how can i modify it?
Upvotes: 0
Views: 1763
Reputation: 120
Use
manager.securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy.validatesDomainName = NO;
May be your server has not been published. So, with this you will not able to recieve internal server error.
Upvotes: 2
Reputation: 3405
It clearly says there was some error from server. It can also happen if you didn't correctly send the parameters. So check if you are sending all the required parameters, its spelling & the case. Also check if you missed any headers
Upvotes: 2