0

I have a rest service which works with DELETE method and http body. But I don't get it to work.

This is what I've tried.

super.manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", nil];

Another attempt:

NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"DELETE"
                                                                             URLString:kApiServiceUserMailBox
                                                                            parameters:nil
                                                                                 error:nil];

    NSDictionary *params =  @{
                              @"email" : email
                              };
    NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:params];

    [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [req setHTTPBody:myData];


    [[super.manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {

        if (!error) {
            NSLog(@"Reply JSON: %@", responseObject);
            NSDictionary* json = [super parseResponse:responseObject];
            NSLog(@"Success: %@", json);
            success();

        } else {
            NSLog(@"Error: %@, %@, %@", error, response, responseObject);
            failure();
        }
    }] resume];
Ricardo
  • 7,921
  • 14
  • 64
  • 111

1 Answers1

0

AFNetworking does not support the combination of DELETE with an HTTP body. This is because the HTTP spec does not require such support.

See Is an entity body allowed for an HTTP DELETE request?

Community
  • 1
  • 1
Avi
  • 7,469
  • 2
  • 21
  • 22