angular.js - angular4 makes a post request and the server displays OPTIONS
ringa_lee
ringa_lee 2017-05-16 13:18:24
0
1
1430

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);
}

Use postman to request to display the post request normally

ringa_lee
ringa_lee

ringa_lee

reply all(1)
过去多啦不再A梦

What host are you running the POST request from? Angular will have an Options when making cross-domain requests, which seems to check whether cross-domain is allowed. In my current project, the front-end and back-end domain names are different, so Options and Request appear at the same time, which was not the case when they used the same domain name.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template