文章詳情頁
angular.js - angular4 發出post請求 服務端顯示OPTIONS
瀏覽:282日期:2024-09-14 10:17:57
問題描述
private headers = new Headers({’Content-Type’: ’application/json’});
private url = ’localhost:3000/users/register’; constructor(private http: Http) { }registerEmail(link:string , email: string , password: string): Promise<any> {return this.http .post(this.url, JSON.stringify({email: email , password: password}), {headers: this.headers}) .toPromise() .then(res => res.json().data) .catch(this.handleError);}
用postman請求正常顯示post請求
問題解答
回答1:你運行POST請求的主機是什么?angular在跨域請求的時候會有一個Options,好像是檢查是否允許跨域的。我目前的項目里前后端域名不一樣的,也是Options和Request同時出現,以前同域名的時候沒有。
相關文章:
排行榜
