我想在 Windows 应用商店应用程序中使用 TheMovieDb Api。
对于 Windows Phone 8,我使用了 WebClient :
WebClient client = new WebClient();
client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://api.themoviedb.org/3/search/movie?api_key=" + key + "&query=" + movieName));
private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
RootObject resultat = JsonConvert.DeserializeObject<RootObject>(e.Result);
idMovie = resultat.results.FirstOrDefault().id.ToString();
}
}
如何在 Windows 8 应用程序中做到这一点?
我试过了
HttpClient http = new System.Net.Http.HttpClient();
string response = await http.GetStringAsync("http://api.themoviedb.org/3/search/movie?api_key=" + key + "&query=" + movieName);
return response;
但我收到一个错误:
响应状态码不表示成功:406(不可接受)
谢谢
编辑 :
好的,我必须添加
http.DefaultRequestHeaders.Add("accept", "Application/JSON");