I use AFHTTPRequestOperationManager for query data from service, but i want set data for POST json data parameters to service.
Thank you for answer.
I use AFHTTPRequestOperationManager for query data from service, but i want set data for POST json data parameters to service.
Thank you for answer.
You can simply do this:
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager POST:@"yourUrl" parameters:yourParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
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];