我正在尝试使用来自Mashape的API。当我测试端点(JSON响应)时,一切正常,但它们给出的objective-c应用程序就绪的代码示例不起作用,我得到以下错误:

这是我的代码:
- (IBAction)loadJson:(id)sender
{
NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"xxxxxxxxx", @"X-Mashape-Authorization", nil];
NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:[NSURL URLWithString:@"<file url>"], @"files", @"", @"urls", nil];
HttpJsonResponse* response = [[Unirest post:^(BodyRequest* request) {
[request setUrl:@"https://lambda-face-recognition.p.mashape.com/detect"];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJson];
}有什么办法可以解决这个问题吗?
谢谢!
发布于 2013-07-13 13:39:02
code examples显示的实际上是代码应该是什么样子:
NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"accept", nil];
NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"parameter", @"bar", @"foo", nil];
HttpJsonResponse* response = [[Unirest postEntity:^(BodyRequest* request) {
[request setUrl:@"http://httpbin.org/post"];
[request setHeaders:headers];
// Converting NSDictionary to JSON:
[request setBody:[NSJSONSerialization dataWithJSONObject:headers options:0 error:nil]];
}] asJson];或者,也许是这个:
NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"accept", nil];
NSURL file = nil;
NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"parameter", file, @"file", nil];
HttpJsonResponse* response = [[Unirest post:^(MultipartRequest* request) {
[request setUrl:@"http://httpbin.org/post"];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJson];https://stackoverflow.com/questions/17626947
复制相似问题