search

Home  >  Q&A  >  body text

angular.js - angular4 makes a post request and the server displays OPTIONS

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_leeringa_lee2753 days ago1431

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:20:24

    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.

    reply
    0
  • Cancelreply