J'ai un WEB API
qui ont CRUD
opération. Pour tester, j'ai créé un Console application
. Créer et GET tous les détails fonctionnent bien. Maintenant, je veux obtenir le produit en utilisant le champ id
. Ci-dessous mon codeGET tous les produits en utilisant le champ 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;
A client.GetAsync(path,id)
l'id me donne erreur de cannot convert string to system.net.http.httpcompletionoption
. Pour cela, j'ai vérifié tous les articles qui s'y rapportent. Mais toujours incapable de trouver la bonne solution.
Toute aide serait très appréciée
J'ai trouvé quelques solutions [ici] (https://stackoverflow.com/questions/14520762/system-net-http-httpcontent-ne-contient-pas-une-définition-pour-readasasync-an). S'il vous plaît essayez-le. –