如何记录AFHTTPRequestOperationManager请求?

时间:2014-03-27 16:09:09

标签: ios objective-c afnetworking-2

我在使用RESTfull网络服务时遇到了一些问题,而且我试图使用NSLog将我的请求视为文本。我试过这个:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
...
 [manager POST:urlString parameters:mutableParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
...
   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Response:  %@", [operation description]) ;
        if (block) {
            block(error);
        }

        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", manager.requestSerializer.debugDescription);
        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", manager.requestSerializer.description);
        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", operation.request.HTTPBodyStream);
        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", operation.request);
        NSLog(@"-------------------------------");
        NSLog(@"Error: %@", error);
        NSLog(@"-------------------------------");

}];

有没有办法从AFHTTPRequestOperationManager(AFNetworking 2)NSLog请求?

1 个答案:

答案 0 :(得分:4)

看一下POST方法:

 [manager POST:urlString parameters:mutableParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

您在成功阻止中有AFHTTPRequestOperation *operationid responseObject

你可以做的最好的事情是:

NSLog(@"AFHttpRequestOperation %@", operation);

并设置断点,以便检查那里发生的事情:

enter image description here

您希望了解有关该操作的请求?

不完全记录但this answer解释了如何将NSURLRequest转换为NSString