如何记录UniRest结果

时间:2014-01-20 02:02:27

标签: objective-c http nslog unirest

我正在使用UniRest作为目标c,我正在向我的服务器发出请求。

#import <Foundation/Foundation.h>
#import "Essay.h"
#import "grammarCheck.h"

int main(int argc, const char * argv[])
{
    NSDictionary* headers = @{@"accept": @"application/json"};
    NSDictionary* parameters = @{@"parameter": @"value", @"foo": @"bar"};

    [[UNIRest get:^(UNISimpleRequest* request) {
        [request setUrl:@"http://thomaswd.net:8081/?language=en&text=my+text"];
        [request setHeaders:headers];
        [request setParameters:parameters];
    }] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
        // This is the asyncronous callback block
        NSInteger code = [response code];
        NSDictionary* responseHeaders = [response headers];
        UNIJsonNode* body = [response body];
        NSData* rawBody = [response rawBody];

        NSLog(@"%@",rawBody);
    }];

    return 0;
}

但是,NSLog(@"%@",rawBody);未记录结果。知道为什么吗?

1 个答案:

答案 0 :(得分:1)

return 0;

之前添加此行
[[NSRunloop currentRunLoop] run];

启动runloop以处理异步请求