0

I use AFHTTPRequestOperationManager for query data from service, but i want set data for POST json data parameters to service.

Thank you for answer.

Love Thailand
  • 769
  • 10
  • 12
  • http://stackoverflow.com/questions/20047090/post-request-with-afhttprequestoperationmanager-not-working ? – Larme Jun 24 '14 at 09:30

2 Answers2

0

You can simply do this:

AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];

[operationManager POST:@"yourUrl" parameters:yourParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

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

}];
Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
0

Thank you, this problem solved.

Example code :

NSMutableURLRequest *requestHTTP = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:my_url] cachePolicy:NSURLRequestReloadIgnoringCacheData  timeoutInterval:10];

[requestHTTP setHTTPMethod:@"POST"];
[requestHTTP setValue:AUTHORIZATION_VALUE forHTTPHeaderField:@"Authorization"];
[requestHTTP setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[requestHTTP setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:requestHTTP];
op.responseSerializer = [AFJSONResponseSerializer serializer];

[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
     NSLog(@"JSON responseObject: %@ ",responseObject);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
     NSLog(@"Error: %@", [error localizedDescription]);

}];

[op start];
Love Thailand
  • 769
  • 10
  • 12