2017-05-01 2 views
0

내가 ASP.NET 코어 웹 API POST 없음 '액세스 제어 - 허용 - 원산지'헤더는

때 Startup.cs

에서 사용할 수있는 기원을 허용 UseCors와 함께 잘 작동 다른 컨트롤러에서 GET 웹 API 메소드가 존재 POST 메서드를 호출하려고하는데 No Access Control-Allow-Origin 헤더가 500 오류와 함께 반환됩니다.

내가 뭘 잘못하고 있니?

getDashboardData() { 
    var self = this; 
    axios.post('http://localhost:5000/product/api/', this.state.clientIdentifiables).then(function (response) {   
      console.log(response); 
     }); 
    } 
+0

오류를 디버그 할 수 있습니까? 그리고 여러분은'api/product /'대신'/ product /'POST를합니다. –

+0

API/제품을 수정하여 주셔서 감사합니다. 그것은 그 길을 부르고 있습니다. – ParleParle

+2

Funnily enough, @IlyaChumakov 디버그 오류 질문에 대답 할 수 없어서 디버깅을 시작하고 문제를 발견했습니다. – ParleParle

답변

1

내가 Startup.cs

의 ConfigureServices 방법의 의존성 주입 항목을 추가하는 것을 잊었다 :

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 메소드를 호출하고 있습니다

public void ConfigureServices(IServiceCollection services) 
     { 
      services.AddMvc(); 
      services.AddTransient<IClientManager, ClientManager>(); 
      services.AddTransient<IClientRepository, ClientRepository>(); 

      // added the following and it hit the web api method correctly 
      services.AddTransient<IProductManager, ProductManager>(); 
      services.AddTransient<IProductRepository, ProductRepository>(); 
     } 
관련 문제