KexAri
KexAri

Reputation: 3977

Trouble using AFNetworking for x-www-form-urlencoded POST

I'm having trouble using AFNetworking for x-www-form-urlencoded POST. My code is as follows:

    NSString *uniqueIdentifier = @"Bob's iPhone";
    NSString *code = self.textField.text;



    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:@"1", @"rw_app_id",code,@"code",uniqueIdentifier,@"device_id", nil];
    [manager POST:@"http://www.somesite.co/promos/" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@",error);
    }];

I am getting the error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo=0x7f8f8bf49550 {NSUnderlyingError=0x7f8f8bf59910 "Request failed: unacceptable content-type: text/html"

I googled around to try and fix this and changed the request serializer with:

manager.requestSerializer=[AFHTTPRequestSerializer serializer];

No luck there. I have my server working fine for these types of requests using NSURLSession. But I want to get it working for AFNetworking. Could someone give me some pointers to what I might be doing wrong please?

Upvotes: 0

Views: 716

Answers (1)

Mobile Developer
Mobile Developer

Reputation: 5760

this should help

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

or use this one for responseSerializer instead of requestSerializer

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

Upvotes: 1

Related Questions