我正在尝试从OMDb API
中获取电影数据OMDb提供的响应有一个错误的内容类型,但我能够绕过这个。 但是,我仍然收到来自AFNetworking的错误:
获取IMDBSingleMovieData时出错:错误 Domain = NSCocoaErrorDomain Code = 3840“操作不可能 完成。 (可可错误3840.)“(JSON文本没有以数组或 允许片段未设置的对象和选项。)UserInfo = 0x10a7451d0 {NSDebugDescription = JSON文本不是以数组或对象开头的 允许片段未设置的选项。}
代码:
// add url request parameters
NSDictionary* parameters = @{ @"i" : [NSString stringWithFormat:@"tt%d", identifier] };
// run the request operation
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager POST:@"http://www.omdbapi.com" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.singleIMDBMovieData = [NSDictionary dictionaryWithDictionary:responseObject];
[self.delegate updateIMDBMovieDetails];
NSLog(@"Object returned %@", self.singleIMDBMovieData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error while fetching IMDBSingleMovieData: %@", error);
}];
我该怎么做才能解决这个问题? 来自API的示例回复:http://www.omdbapi.com/?i=tt0993846
答案 0 :(得分:1)
您正在提出POST
请求但是您想要获取数据,因此您应该使用GET
:
[manager GET:@"http://www.omdbapi.com" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.singleIMDBMovieData = [NSDictionary dictionaryWithDictionary:responseObject];
[self.delegate updateIMDBMovieDetails];
NSLog(@"Object returned %@", self.singleIMDBMovieData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error while fetching IMDBSingleMovieData: %@", error);
}];