1

我正在尝试将一些信息从我的应用程序发送到我的 PHP 服务器端程序。

当我尝试使用PHP Arrayas UnitTest 发送相同的数据时,它可以工作。所以我不知道为什么 AFNeworking 认为这不起作用。

为了调试问题,我需要能够看到完整的 HTTP 消息。

我怎么能看到普通(非 JSON)错误(HTTP 响应)?

我虽然这样operation.JSONReadingOptions = NSJSONReadingAllowFragments;做可以解决问题,但没有工作,或者我没有把它放在正确的地方

谢谢

我的错误:

2013-06-05 10:52:37.990 iGym[9407:c07]Request failed with error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x96db4d0 {NSDebugDescription=Garbage at end.}, {
NSDebugDescription = "Garbage at end.";

}

我的 Objective-c 代码

User* myUser = [self getCurrentUser];
    NSURL *url = [[NSURL alloc]initWithString:@"http://192.168.1.64/"];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];

    NSDictionary *params = @{@"register":@"true",
                             @"email":@"as234d",
                             @"userID":(myUser.idUserExternal ? myUser.idUserExternal: @"NO"),
                             @"userDetails":@{@"needUsername":(myUser.nickname ? @"NO": @"YES"),
                                              @"username":( myUser.nickname  ? myUser.nickname : _input.text),
                                              @"language":(myUser.language? myUser.language: @"0"),
                                              @"name":(myUser.name ? myUser.name : @"0"),
                                              @"surname":(myUser.surname ? myUser.surname : @"0"),
                                              @"country":(myUser.country ? myUser.country : @"0"),
                                              @"dob":(myUser.dob ? myUser.dob : @"0"),
                                              @"city":(myUser.city ? myUser.city : @"0"),
                                              @"height":(myUser.height ? myUser.height : @"0"),
                                              @"weight":(myUser.weight ? myUser.weight : @"0"),
                                              @"metricType":(myUser.metricSystem ? myUser.metricSystem : @"0")
                                            }
                             };
    NSLog(@"%@",params);
    NSURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"igym/bootstrap.php" parameters:params];


    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                                                        success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
                                                                                            NSLog(@"Inside the success block %@",JSON);
                                                                                            if ([JSON objectForKey:@"ok"]) {
                                                                                                [self done:JSON];
                                                                                            }

                                                                                            if ([JSON objectForKey:@"error"]) {
                                                                                                [self tryAgain:JSON[@"error"]];
                                                                                            }
                                                                                        }
                                                                                        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){

                                                               NSLog(@"json text is: %@", JSON);
                                                                                            NSLog(@"Request failed with error: %@, %@", error, error.userInfo);
                                                                                        }];
    operation.JSONReadingOptions = NSJSONReadingAllowFragments;

    [operation start];
4

1 回答 1

9

在您的successorerror块中,您可以NSLog operation.responseStringor operation.responseData。这将为您提供从服务器发送的原始字符串或字节。

于 2013-06-05T18:43:01.370 回答