如何使用AFHTTPSessionManager

时间:2019-04-11 10:26:44

标签: objective-c rest api post afnetworking-3

我是REST API的新手。我正在尝试使用POST方法将一些数据发送到Web api。一切运行良好,直到我尝试将空白数据发送到参数。下面是我的相同代码

[dict setObject:strReqId forKey:@"ReqId"];
[dict setObject:strOrderId forKey:@"OrderId"];
[dict setObject:strScheduleId forKey:@"ScheduleId"];
 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy.validatesDomainName = NO;
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

[manager POST:URLString parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
    NSLog(@"%@",responseObject);

    NSString *strResponse = [NSString stringWithFormat:@"%@",responseObject];
    if (strResponse.length>0)
    {
        if ([strResponse isEqualToString:@"0"])
        {
            UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Warning!", nil)] message:[NSString stringWithFormat:NSLocalizedString(@"Something went wrong. Please try again.", nil)] delegate:self cancelButtonTitle:nil otherButtonTitles:[NSString stringWithFormat:NSLocalizedString(@"OK", nil)],nil];
            [alert3 show];
        }
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)  {

}];

但是当我尝试向任何参数发送空白数据时,

[dict setObject:@"" forKey:@"ReqId"];

我得到一个“ 0”作为回应。 请帮助我。

1 个答案:

答案 0 :(得分:0)

@[]尝试一下。实际上,您必须随此传递任何类型的数据。这里fzr get apps表示空数组。