0

我正在将 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);没有记录结果。知道为什么吗?

4

1 回答 1

1

在前面添加这一行return 0;

[[NSRunloop currentRunLoop] run];

它启动运行循环以处理异步请求

于 2014-01-20T04:22:12.373 回答