The Movie Database Support

The subject pretty much says it all. I am able to get results when I copy paste the URL from my code to the URL bar of a browser. I'm using the code from http://www.codeproject.com/Tips/397574/Use-Csharp-to-get-JSON-Data-from-the-Web-and-Map-i (the downoload serialized json data function). I also generated the classes as it directed and named the root object MovieDBJSON.

One last tidbit; I'm using the first URL for my test: http://api.themoviedb.org/3/movie/550?api_key=. Yup, the one that supposed to be HELLO World, I'm looking for Mr. Fight Club :).

I saw many people mention the Accept Content-Type header so I added w.Headers.Add("Content-Type", "application/json; charset=utf-8");. This had no effect.

My suspicion is that I have something wrong for the WebClient as I'm getting an exception: "The Remote server returned an error: (406) Not Acceptable."

I've made another discovery which more or less confirms the above suspicion. When I apply the sames methods to the API for RottenTomatoes, everything works perfect. This surely sounds like a data transport error between .NET 4.5 WebClient and theMoveDB.org. I've tried updating the header as stated before and had no luck. I'm curious if anyone has gotten this to work. - NOTE: PHP is my first programming language. I'm just starting to get into .NET so there may be a tweak to the WebClient that I am not aware of.

Thank you in advance for your time and assistance,

Sincerely, Brian D Swan brian.swan@gmail.com

3 replies (on page 1 of 1)

Jump to last post

I'm also working on an app that accesses TheMovieDB and RottenTomatoes. I'm using JSON.NET for serialization and HTTPClient for connection. Your right that the RottenTomatoe api works easily. I had no problems with connection to it but I recieved the 406 (Not Acceptable) error for TheMovieDB. I'm using the Postman Chrome extension for testing my REST calls and had no problems getting the data there, but my app keeps getting this error.

I did try setting the Accept header with the content type and so far it's working.

HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

Hey guys,

A 406 (Not Acceptable) means the Accept header is not set to "application/json" or "application/json; charset=utf-8". Brian, you tried setting the Content-Type header. Set your Accept header and you'll be good to go.

Thank you all greatly for your help. It makes sense to me now. The website I was trying to get the header from said to set the accept: as Content-Type... I see the error. I have updated my code as

using (var w = new WebClient()) { var jsonData = string.Empty; // attempt to download JSON data as a string w.Headers.Add("Accept", "application/json");

....

This worked perfectly.

Sincerely, Brian

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

ಲಾಗಿನ್