发布到服务器,将ASIFormDataRequest替换为AFnetworking

时间:2014-03-19 16:40:12

标签: ios http post afnetworking asiformdatarequest

我想在afnetworking做一个帖子请求 这是我的代码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];

我怎样才能在AFnetworking中做同样的丁字裤?

1 个答案:

答案 0 :(得分:1)

不是一个确切的答案,但这是来自我的应用程序的非常相似的POST请求:

-(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是AFHTTPRequestOperationManager的一个实例,初始化为:

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