CRUD
の操作を持つWEB API
があります。テストのために私はConsole application
を作成しました。作成し、すべての詳細が正常に動作しています。今私はid
フィールドを使用して製品を取得したい。以下は私のコードidが私にエラーcannot convert string to system.net.http.httpcompletionoption
を与えているidフィールドを使用してすべての製品を入手する
static HttpClient client = new HttpClient();
static void ShowProduct(Product product)
{
Console.WriteLine($"Name: {product.Name}\tPrice: {product.Price}\tCategory: {product.Category}", "\n");
}
static async Task<Product> GetProductAsyncById(string path, string id)
{
Product product = null;
HttpResponseMessage response = await client.GetAsync(path,id);
if (response.IsSuccessStatusCode)
{
product = await response.Content.ReadAsAsync<Product>();
}
return product;
}
case 3:
Console.WriteLine("Please enter the Product ID: ");
id = Convert.ToString(Console.ReadLine());
// Get the product by id
var pr = await GetProductAsyncById("api/product/", id);
ShowProduct(pr);
break;
client.GetAsync(path,id)
で
すべてのヘルプは非常にstring
ように、第2引数を受け入れ何の方法GetAsync()
がないため、このエラーが出る
私が発見したカップルhttps://stackoverflow.com/questions/14520762/system-net-http-httpcontent-does-not-contain-a-definition-for-readasasync-an)を参照してください。試してみてください。 –