2014-03-27 75 views
3

我在使用RESTfull Web服務時遇到了一些麻煩,我試圖將我的請求看作使用NSLog的文本。我嘗試這樣做:如何記錄AFHTTPRequestOperationManager請求?

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)的要求?

+0

也許請求_not_失敗?你可以調試成功或失敗塊嗎? – Aaron

+0

我的問題是,服務器說我在請求中有一個空字段(json格式)。但我添加了一個斷點來檢查值。它不是空的。所以我想也許問題是在請求結構中...... – Sebastian

+0

因此,服務器不發送迴應? – Aaron

回答

4

,看一下POST方法:

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

你有一個AFHTTPRequestOperation *operation,並在成功塊中的id responseObject

,你能做的最好的事情是把一個:

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

,並設置有一個斷點,這樣你就可以檢查發生的事情有:

enter image description here

你想什麼看看操作的要求?

不完全記錄,但this answer介紹瞭如何的NSURLRequest轉換爲NSString的

+0

感謝您的回答!我的問題是服務器說我在請求中有一個空字段(json格式)。但我添加了一個斷點來檢查值。它不是空的。所以我想也許問題是在請求結構中...... – Sebastian

+0

如果你發送json到服務器有一個請求序列化器設置爲json類型。 – javierfdezg