我正在使用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);
未记录结果。知道为什么吗?
答案 0 :(得分:1)
在return 0;
[[NSRunloop currentRunLoop] run];
启动runloop以处理异步请求