0
votes

My code is here:

AFHTTPRequestOperationManager *managers = [AFHTTPRequestOperationManager manager];

NSMutableDictionary *parDic = [NSMutableDictionary dictionary];

[parDic setObject:@"admin" forKey:@"userId"];

[parDic setObject:@"1" forKey:@"password"];

  [managers POST:@"http://posttestserver.com/post.php?" parameters:par success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
    NSLog(@"sucess");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

It print that:Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/plain"

But when I use kitchen test this request, it works fine.Why?Please help me, thank you very much!

2
This error may be You Not start your operation...[operation start];Kirit Modi
managers.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; add this line and try as mentioned in above link.Ganapathy
Thanks for your answerJerry GaGa

2 Answers

1
votes

Follow the Below Code i Successfully of its

NSString *StringUrl = [NSString stringWithFormat:@"%@?userId=%@&password=%@",YourUrl,@"admin",@"1"];

    NSURLRequest *UrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:StringUrl]];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:UrlRequest];

    operation.responseSerializer = [AFJSONResponseSerializer new];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *OP,id ResponseObj)
     {

         NsLog(@"Success == %@",ResponseObj);


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

         NsLog(@"Error == %@",[error localizedDescription])

     }];

    [operation start];
0
votes

this line worked for me after trying everything else:

operation.responseSerializer = [AFCompoundResponseSerializer serializer];

NSString *strdata =[NSString stringWithFormat:@"{\"objID\":\"%ld\",\"objString\":\"%@\",\"objWidth\":\"%@\",\"objHeight\":\"%@\",\"objStartX\":\"%@\",\"objStartY\":\"%@\",\"objEndX\":\"%@\",\"objEndY\":\"%@\",\"objSnapX\":\"%@\",\"objSnapY\":\"%@\",\"objImage\":\"%@\"}",
                    (long)self.accelerometerObject.objID,
                    self.accelerometerObject.objString.string,
                    self.accelerometerObject.objWidth,
                    self.accelerometerObject.objHeight,
                    self.accelerometerObject.objStartX,
                    self.accelerometerObject.objStartY,
                    self.accelerometerObject.objEndX,
                    self.accelerometerObject.objEndY,
                    self.accelerometerObject.objSnapX,
                    self.accelerometerObject.objSnapY,
                    self.accelerometerObject.objImage];
NSLog(@"%@",strdata);
NSDictionary *parameters = @{
                             @"data" : strdata,
                             };
AFHTTPRequestOperationManager *requestOperationManager = [AFHTTPRequestOperationManager manager];
requestOperationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSString *requestURL = @"http://yourserver.com/dataHandler.asmx/scriptToHandlePost";
requestOperationManager.responseSerializer = [AFCompoundResponseSerializer serializer];
requestOperationManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[requestOperationManager POST:requestURL
                   parameters:parameters
                      success:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"Succeeded:    >>>>>>> %@",strdata);
 }
                      failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     NSLog(@">>>>>>>>>>>failed %@",error);
 }];