【发布时间】:2015-03-24 02:13:55
【问题描述】:
这是我第一次尝试调用 API,但我有点挣扎。我不断收到错误消息,我计划使用 json 响应来填充我的对象。 OMDB api 说明在这里(虽然没有帮助):http://www.omdbapi.com/
private static async Task RunAsync()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://www.omdbapi.com/?");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("t=Captain+Phillips&r=json").Result;
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("Error with feed");
}
}
}
【问题讨论】:
-
你遇到了什么错误?