Web API で動作するデモ モバイル アプリケーションを作成しています。私はこのサイトに従っています:
これは、Web API を呼び出す方法です。
class Program
{
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:9000/");
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
}
API 関数の呼び出し方法は次のとおりです。
HttpResponseMessage response = client.GetAsync("api/products").Result; // Blocking call!
if (response.IsSuccessStatusCode)
{
// Parse the response body. Blocking!
var products = response.Content.ReadAsAsync<IEnumerable<Product>>().Result;
foreach (var p in products)
{
Console.WriteLine("{0}\t{1};\t{2}", p.Name, p.Price, p.Category);
}
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
この行がわかりません:
HttpResponseMessage response = client.GetAsync("api/products").Result;
api/products
アドレスを使用する場合、何と呼ばれますか? モデル、API のコントローラー クラス、またはその他の何か?