post to server ,replace ASIFormDataRequest to AFnetworking

191 views Asked by At

i want to do a post request in afnetworking
this is my code whit ASI:

NSURL *mainurl = [NSURL URLWithString:@"xxxx/api/xxx/"];

    ASIFormDataRequest *requestt = [ASIFormDataRequest requestWithURL:mainurl];

    [requestt addPostValue:GETUnicidentifire forKey:@"UniqueId"];
    [requestt addPostValue:JsonOrderDetail   forKey:@"jsonProduct"];
    [requestt addPostValue:BranchId          forKey:@"BranchId"];
    [requestt addPostValue:OrderToTime       forKey:@"OrderToTime"];

    [requestt setCompletionBlock:^{
        // Process the response




    }];
    [requestt setFailedBlock:^{
        NSError *error = [requestt error];

how can i do the same thong in AFnetworking ?

1

There are 1 answers

0
David Berry On

Not an exact answer, but here's a very similar POST request from my application:

-(void)setGpsLocation:(CLLocation*)location success:(TPScopeInterfaceSuccess)success failure:(TPScopeInterfaceFailure)failure
{
    [_manager POST:@"gps/"
        parameters:@{
                     @"lat":@(location.coordinate.latitude),
                     @"lon":@(location.coordinate.longitude),
                     @"height":@(location.altitude),
                     }
     constructingBodyWithBlock:nil
           success:success
           failure:failure];
}

_manager is an instance of AFHTTPRequestOperationManager initialized as:

_manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.1/"]];