【发布时间】:2014-06-24 09:27:49
【问题描述】:
我使用 AFHTTPRequestOperationManager 从服务中查询数据,但我想为服务设置 POST json 数据参数的数据。
谢谢你的回答。
【问题讨论】:
标签: objective-c afnetworking json-rpc
我使用 AFHTTPRequestOperationManager 从服务中查询数据,但我想为服务设置 POST json 数据参数的数据。
谢谢你的回答。
【问题讨论】:
标签: objective-c afnetworking json-rpc
你可以这样做:
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager POST:@"yourUrl" parameters:yourParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
【讨论】:
谢谢,这个问题解决了。
示例代码:
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];
【讨论】: