這可能是一個愚蠢的問題,但這裏是我的簡單的WebAPI 2方法當我的ajax調用無法完成時,SoapUI如何繞開CORS問題?
public class ProductsController : ApiController
{
Product[] products = new Product[]
{
new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 },
new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M },
new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M }
};
public IEnumerable<Product> GetAllProducts()
{
return products;
}
現在,如果我運行它,在我的電腦運行在http://localhost:3145/Products
,我可以看到的產品作爲XML
它也適用於使用的soapUI
但現在,如果我嘗試用一個HTML文件,該JavaScript訪問此
<script type="text/javascript">
function GetProducts() {
$.ajax({
url: "http://localhost:3145/Products",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.length; i++)
$('#myDiv').append(data[i].Category).append("<br/>");
},
error: function (xhr, status) {
alert(xhr);
}
});
}
</script>
</head>
<body onload="GetProducts()">
<h1>My App</h1>
<div id="myDiv"></div>
我得到的CORS錯誤
如何SOAP UI不在這裏時,它是使用HTTP以及得到一個錯誤?
感謝