1
votes

I am trying to fetch movie data from the OMDb API

The response OMDb provides has a wrong content-type but I was able to circumvent this. However, I still receive errors from AFNetworking:

Error while fetching IMDBSingleMovieData: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x10a7451d0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

Code:

// 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);
}];

What can I do to fix this? Sample response from API: http://www.omdbapi.com/?i=tt0993846

1
I suggest to use TMDB instead; it has some good wrappers library, such as iOS themoviedb.org/documentation/api/wrappers-librariessekmo
Yes but I already have an IMDB id I want to search data for. TMBD does not offer that at this pointedwardmp

1 Answers

1
votes

You're making a POST request but you want to fetch the data, so you should be using a 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);
}];