【问题标题】:How can I log AFHTTPRequestOperationManager request?如何记录 AFHTTPRequestOperationManager 请求?
【发布时间】:2014-03-27 16:09:09
【问题描述】:

我在使用 RESTfull Web 服务时遇到了一些问题,我正在尝试使用 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(@"-------------------------------");

}];

有没有办法 NSLog 来自 AFHTTPRequestOperationManager (AFNetworking 2) 的请求?

【问题讨论】:

  • 也许请求没有失败?您可以调试成功或失败块吗?
  • 我的问题是服务器说我的请求中有一个空字段(json格式)。但是我添加了一个断点来检查值。它不为空。所以我认为问题可能出在请求结构中......
  • 所以服务器没有发回响应?

标签: ios objective-c afnetworking-2


【解决方案1】:

看看POST方法:

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

成功块中有一个AFHTTPRequestOperation *operation 和一个id responseObject

你能做的最好的事情就是放一个:

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

并在那里设置一个断点,以便您可以检查那里发生的事情:

您想查看关于操作请求的哪些内容?

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

【讨论】:

  • 感谢您的回答!我的问题是服务器说我在请求中有一个空字段(json格式)。但是我添加了一个断点来检查值。它不为空。所以我认为问题可能出在请求结构中......
  • 如果您将 json 发送到服务器,请查看将请求序列化程序设置为 json 类型。
猜你喜欢
  • 2013-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多