2017-08-11 108 views
0

Angular2 Get請求工作正常,但POST請求給我error.this是我的要求Angular2 Get請求工作正常,但POST請求給我的錯誤

url = environment.API + "products/"; 
    headers = new Headers({ 'Content-Type': 'application/json' }); 
    options = new RequestOptions({ headers: this.headers }); 
    constructor(private http:Http) { 
    } 
    getProductsList(data): Promise<any> { 
     return this.http.post(this.url+'getproductsbyfilters', JSON.stringify(data), this.options).toPromise() 
       .then(this.extractData) 
        .catch(this.handleErrorPromise); 
    } 
+0

你得到的錯誤是什麼? –

+0

XMLHttpRequest無法加載http:// localhost:8090/api/front/products/getproductsbyfilters。對預檢請求的響應不會通過訪問控制檢查:請求的資源上不存在「訪問控制 - 允許來源」標頭。因此不允許訪問Origin'http:// localhost:4200'。 –

+0

看起來像一個CORS問題,允許通過與您的服務器不同的來源訪問POST方法(您的前端位於localhost:4200,而您的api位於localhost:8090,兩個不同的來源) –

回答

0

我補充說,在Web.config文件,並開始工作的罰款那...

<handlers> 
     <remove name="OPTIONSVerbHandler"/> 
</handlers>