Υποστήριξη για το 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 απαντήσεις(στη σελίδα 1 από 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

Δεν μπορείτε να βρείτε κάποια ταινία ή σειρά; Συνδεθείτε για να τη δημιουργήσετε.

Σε όλες τις σελίδες

s Εστίαση στη μπάρα αναζήτησης
p Άνοιγμα μενού προφίλ
esc Κλείσιμο ανοιχτού παραθύρου
? Άνοιγμα παραθύρου συντομεύσεων πληκτρολογίου

Στις σελίδες μέσων

b Επιστροφή στην προηγούμενη σελίδα(ή στην αρχική σελίδα όταν είναι εφικτό)
e Μετάβαση στη σελίδα επεξεργασίας

Στις σελίδες κύκλων σειρών

(Δεξιό βέλος) Μετάβαση στον επόμενο κύκλο
(Αριστερό βέλος) Μετάβαση στον προηγούμενο κύκλο

Στις σελίδες επεισοδίων σειρών

(Δεξιό βέλος) Μετάβαση στο επόμενο επεισόδιο
(Αριστερό βέλος) Μετάβαση στο προηγούμενο επεισόδιο

Σε όλες τις σελίδες εικόνων

a Άνοιγμα παραθύρου προσθήκης εικόνας

Σε όλες τις σελίδες επεξεργασίας

t Άνοιγμα επιλογέα μετάφρασης
ctrl+ s Υποβολή φόρμας

Στις σελίδες συζήτησης

n Δημιουργία νέας συζήτησης
w Ρύθμιση κατάστασης παρακολούθησης
p Ρύθμιση ως δημόσια/ιδιωτική
c Ρύθμιση ανοίγματος/κλεισίματος
a Άνοιγμα δραστηριότητας
r Απάντηση στη συζήτηση
l Μετάβαση στην τελευταία απάντηση
ctrl+ enter Υποβολή μηνύματος
(Δεξιό βέλος) Επόμενη σελίδα
(Αριστερό βέλος) Προηγούμενη σελίδα

Ρυθμίσεις

Θέλετε να αξιολογήσετε ή να προσθέσετε αυτό το στοιχείο σε μια λίστα;

Σύνδεση