AFNetworking request error: inappropriate content type: text / html

I am trying to send a POST request to a server and I still cannot do this. Please help me, which is wrong.

Generic init instance:

- (id)init{
self = [self initWithBaseURL:[NSURL URLWithString:kBaseURL]];
if(self) {
    self.
    self.responseSerializer = [AFJSONResponseSerializer serializer];
    [self.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"password"];
    parsingQueue = dispatch_queue_create("com.company.queue.parser",NULL);
}
return self;

message body:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[FSApplicationManager sharedInstance].userToken, @"user_token", nil];
[params setObject:[NSNumber numberWithDouble:userId] forKey:@"user_id"];
[params setObject:[NSNumber numberWithDouble:filmId] forKey:@"film_id"];
[params setObject:[NSNumber numberWithBool:NO] forKey:@"sendCopy"];

if([subject length]>0){
    [params setObject:subject forKey:@"subject"];
}
[params setObject:message forKey:@"message"];

NSString *URLString = [NSString stringWithFormat:@"%@%@", kBaseURL, kAPISendMessageToUser];

NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST"
                                                               URLString:URLString
                                                              parameters:params
                                                                   error:nil];

[request addValue:[self signatureWithURL:[request.URL absoluteString] requestBody:[[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding]] forHTTPHeaderField:@"X-SERVAPI-Signature"];
[request addValue:pub forHTTPHeaderField:@"X-SERVAPI-PublicKey"];

AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id response){
    NSLog(@"%@", response);

} failure:^(AFHTTPRequestOperation *operation,  NSError *error){
    NSLog(@"%@, \n response %@", error, operation.responseObject);
}];

[self.operationQueue addOperation:operation];

return operation;

The error I am getting is:

Domain Error = AFNetworkingErrorDomain Code = -1011 "Request Error: Internal Server Error (500)" UserInfo = 0xcf0c2f0 {NSErrorFailingURLKey = https://ppd.someserver.com/api/user/send-message , NSLocalizedDescription = Request failed: error internal server (500), NSUnderlyingError = 0xcf06ce0 "Request error: not acceptable content-type: text / html", AFNetworkingOperationFailingURLResponseErrorKey = {URL: https://ppd.someserver.com/api/user/send- message} { : 500, {      = ;      "Content-Encoding" = gzip;      "Content-Length" = 1412;      "Content-Type" = "text/html; charset = UTF-8";     Date = "Sun, 14 Dec 2014 13:46:57 GMT";     P3P = "CP = \" NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM\ ";     Server = Apache;     Vary =" Accept-Encoding ";     " X-Powered-By "=" PHP/5.3.3-7 + squeeze19"; }}},

, , , :

, , POST, : Content-Type: application/x-www-form-urlencoded;

+4
2

HTML. , , , HTML.

AFHTTPResponseSerializer, HTML, , , . Charles . , , 500, HTML a .

, , , API. ( , camelCase ), API, , .

Content-Type, AFNetworking ( application/x-www-form-urlencoded, , .

API Objective-C/AFNetworking, , Charles - . , , , , API Objective-C/AFNetworking.

+5

, HTML- . :

  • , json.

  • , : self.responseSerializer :

    self.operationManager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

/html . - - .

+7

All Articles