Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetwoking POST call returns 500 internal server error but server got request parameter

I'm trying to upload my payment success message to my server. Below are my code

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",myTokenString] forHTTPHeaderField: @"Authorization"];


AFHTTPRequestOperation *operation = [manager POST:@"MYAPI" parameters:paramsDict success:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSLog(@"%@",responseObject);


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@"%@",error.localizedDescription);

}];
[operation start];

But I'm getting error code 500 (internal server error). But my server has all the information and API call is success. Can anyone please help me understand why it's entering the error block?

like image 593
Ajith Kumar Avatar asked Apr 28 '16 13:04

Ajith Kumar


People also ask

What causes a 500 Internal server Error?

The 500 Internal Server error could be caused by an error during the execution of any policy within Edge or by an error on the target/backend server. The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request.

What is 500 unexpected Error?

Unexpected Error : ( An error occurred and your request couldn't be completed. Please try again. Membership in the Recipient Management role group enables users to do administrative tasks, such as creating and modifying Exchange recipient objects.


1 Answers

In new AFNetworking version, you don't need a initialize for AFHTTPRequestOperation class to handle request so you just adjust your code as following:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",myTokenString] forHTTPHeaderField: @"Authorization"];

[manager POST:@"MYAPI" parameters:paramsDict success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@",error.localizedDescription); 
}];
like image 64
brianha289 Avatar answered Oct 27 '22 01:10

brianha289