在Post(Iphone)期间无法在Afnetworking 3.0中获得Param

时间:2016-06-23 10:28:20

标签: iphone afnetworking

我使用以下代码从Php服务器获取数据。我想将id传递给URL,但AfNetworking没有得到组合url和id。

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = config.class)
public class myTester extends SharedJavaSparkContext implements Serializable{

我已经检查过Json Response,我得到了以下回复:

 - (void)requestServerWithMethod: (NSURL )baseURL andParams:(NSDictionary   )params
{
if (![self isReachable]) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Please check your internet connection and try again." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [alertView show];

    return;
}

NSLog(@"params: %@", params);

NSString *url = [baseURL absoluteString];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];// change json response
[manager.requestSerializer setValue:@"Content-Type" forHTTPHeaderField:@"text/html"];
//        UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];  //using for show loader
//        MBProgressHUD *hud= [MBProgressHUD showHUDAddedTo:window animated:YES];
//      hud.mode = MBProgressHUDModeAnnularDeterminate;
//     hud.activityIndicatorColor = [UIColor whiteColor];

//  hud.labelText = @"Loading...";
[manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * Nonnull task, id  Nullable JSON) {
    NSLog(@"success!");

    [_delegate serverDidReceiveResponse:JSON];
    //   [MBProgressHUD hideHUDForView:window animated:YES];

} failure:^(NSURLSessionDataTask  _Nullable task, NSError  _Nonnull error) {
    NSLog(@"error: %@", error);

    [_delegate serverDidReceiveError:error];
    //   [MBProgressHUD hideHUDForView:window animated:YES];
}];

0 个答案:

没有答案