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 发送信息
(右箭头)下一页
(左箭头)前一页

设置

想给这个条目评分或将其添加到片单中?

登录

还不是会员?

注册加入社区