0
私は ASP.NETコアのWeb API POSTいいえ「アクセス制御 - 許可 - 起源」ヘッダーは
ときStartup.cs
で有効に任意の起源を可能UseCorsで細かい作業を別のコントローラでGETウェブAPIメソッドを持っている存在でありますPOSTメソッドを呼び出そうとしましたが、No 'Access-Control-Allow-Origin'ヘッダーが500エラーとともに返されました。私は間違っていますか?
using System.Collections.Generic;
using CrossSell.Business.Exceptions;
using CrossSell.Business.Interfaces;
using CrossSell.Entities;
using Microsoft.AspNetCore.Mvc;
namespace CrossSell.API.Controllers
{
[Produces("application/json")]
[Route("api/Product")]
public class ProductController : Controller
{
private readonly IProductManager productManager;
public ProductController(IProductManager productManager)
{
this.productManager = productManager;
}
// POST: api/Product
[HttpPost]
public IEnumerable<Opportunity> Post([FromBody]ClientIdentifiable[] clients)
{
try
{
return productManager.GetCrossSellOpportunities(clients);
}
catch (NoInForceOrHistoricalPoliciesException)
{
return new[] { new Opportunity(true, "No In Force or historical policies") };
}
}
}
}
私は(ローカルホスト上で実行されます:3000):アプリに反応からPostメソッドを呼んでいる
getDashboardData() {
var self = this;
axios.post('http://localhost:5000/product/api/', this.state.clientIdentifiables).then(function (response) {
console.log(response);
});
}
エラーをデバッグできませんか。そしてあなたは 'api/product /'の代わりに '/ product /'をPOSTします。 –
api/productを修正していただきありがとうございます。その道を呼んでいます。 – ParleParle
Funnily enough、@IlyaChumakov @IlyaChumakov私はあなたのデバッグにエラーの質問に答えることができませんでしたので、私はデバッグを開始し、問題を発見しました。 – ParleParle