我想連接到堆棧溢出API作爲我的第一個API調用之一,但我掙扎。連接到堆棧溢出API
有人能告訴我爲什麼這段代碼沒有返回成功代碼嗎?
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("https://api.stackexchange.com/");
var response = await client.GetAsync("questions");
if (response.IsSuccessStatusCode)
{
}
else
{
Console.WriteLine(response.ToString());
}
}
它返回什麼代碼? – xDaevax 2014-09-02 18:46:28
您是否嘗試過在瀏覽器中點擊「http:// api.stackexchange.com/questions」?它給你一個400 – Jonesopolis 2014-09-02 18:49:01
'{「error_id」:400,「error_message」:「site is required」,「error_name」:「bad_parameter」}' – jball 2014-09-02 18:49:28