Posting data to server and response is :{“Message”:“An error has occurred.”}

后端 未结 3 1339
长情又很酷
长情又很酷 2021-01-26 08:53

I have tried many methods of posting data to server but none of them worked and only response am getting is:

{\"Message\":\"An error has occurred.\"}

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-26 09:08

    BASE_URL = PASS_YOUR_URL _params = parameters // AS NSMutableDictionary Try this.

     NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
     [params setValue:YOUR_VALUE forKey:@"cust_id"]; // here pass your field that you want to pass as parameter. 
     [params setValue:YOUR_VALUE forKey:@"Prod_ID"];
    
     NSString *url = [BASE_URL stringByAppendingString:_action];
    
     AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:url]];
     manager.requestSerializer = [AFHTTPRequestSerializer serializer];
     manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    [manager POST:url parameters:_params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSLog(@"response = %@", responseObject);
            if( _success )
            {
                _success( responseObject ) ;
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSLog(@"error = %@", error);
                if( _failure )
                {
                    _failure( error) ;
                }
    }];
    

提交回复
热议问题