Suporte do The Movie Database

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 respostas (na página 1 de 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

Não consegue encontrar um certo filme ou série? Inicie sessão e adicione-o.

Geral

s focus the search bar
p abrir menu do perfil
esc close an open window
? open keyboard shortcut window

Em páginas de Média

b go back (or to parent when applicable)
e ir para a página de edição

Em páginas de temporadas de séries

(seta para a direita) ir para a próxima temporada
(seta para a esquerda) ir para a temporada anterior

Em Páginas de Episódios de Séries

(seta para a direita) ir para o próximo episódio
(seta para a esquerda) ir para o episódio anterior

Em Todas as Páginas de Imagens

a abrir janela para adicionar imagem

Em Todas as Páginas de Edição

t open translation selector
ctrl+ s submit form

Em Páginas de Discussão

n criar uma nova discussão
w toggle watching status
p toggle public/private
c toggle close/open
a abrir actividade
r reply to discussion
l ir para a última resposta
ctrl+ enter submit your message
(seta para a direita) página seguinte
(seta para a esquerda) página anterior

Definições

Deseja classificar ou adicionar este item a uma lista?

Iniciar Sessão

Ainda não é um membro?

Crie uma Conta e Adere a Comunidade