我不知道如何在浏览器中查看get api结果。我试图让这个网址(http://localhost:8269/api/getproducts
)的响应,但得到一个错误:无法获取webapi结果
<Error>
<Message>
No HTTP resource was found that matches the request
URI 'http://localhost:8269/api/getProducts'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'getProducts'.
</MessageDetail>
</Error>
public class ProductsController : ApiController
{
Product[] products = new Product[]
{
new Product { ProductId=1,ProductName="samsung",ProductCategory="mobile",ProductPrice=7889 },
new Product { ProductId=1,ProductName="nokia",ProductCategory="mobile",ProductPrice=7844 },
new Product { ProductId=1,ProductName="lg",ProductCategory="mobile",ProductPrice=7887 },
new Product { ProductId=1,ProductName="xiomi",ProductCategory="mobile",ProductPrice=7856 },
new Product { ProductId=1,ProductName="htc",ProductCategory="mobile",ProductPrice=7833 }
};
public IEnumerable getProducts()
{
return products;
}
}
你试过 - http:// localhost:8269/api/products/getproducts? – Manoj
是的我试过了,出现错误('ObjectContent'1'类型未能序列化内容类型'application/xml; charset = utf-8'的响应正文)。 – Swapna
请编辑你的ajax方法,你必须设置ContentType :应用程序/ XML中的Ajax请求? – Manoj