ios - About AFNetworking 2 -
how can dynamically change block afhttprequestoperationmanager post, get, delete...
the original example has http method fixed has post:
afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; nsdictionary *parameters = @{@"foo": @"bar"}; [manager post:@"http://example.com/resources.json" parameters:parameters success:^(afhttprequestoperation *operation, id responseobject) { nslog(@"json: %@", responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error); }];
what wanna know, there way insert http method dynamically? dummy example:
afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; nsdictionary *parameters = @{@"foo": @"bar"}; --> [manager @"post or or delete":@"http://example.com/resources.json" parameters:parameters <---success:^(afhttprequestoperation *operation, id responseobject) { nslog(@"json: %@", responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error); }];
sorry if i'm making dumb question.
best regards.
yes possible. need set nsurlrequest
(or nsmutableurlrequest
) yourself:
afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; // set custom reqeust serializer here, if needed nsmutableurlrequest *request = [manager.requestserializer requestwithmethod:@"get" urlstring:[nsurl urlwithstring:@"http://example.com/resources.json"] parameters:parameters error:nil]; [manager httprequestoperationwithrequest:request success:^(afhttprequestoperation *operation, id responseobject) { nslog(@"json: %@", responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error); }];
i haven't run code as-is, see general idea. if using custom request serializer, want set indicated in comment above.
simply replace @"get" @"post" or "@delete".
Comments
Post a Comment