虽然我的后端工作,我得到Angular 5的状态代码500

时间:2018-05-14 10:55:41

标签: angular forms laravel-5

我有一个Laravel后端,它允许我管理用户。我用Postman测试了后端。我可以创建一个用户并登录。现在我想用Angular登录。但是,我获得了500分,所以这并没有多少开始。我觉得这是一个标题问题。但我不知道为什么。

我的后端:

https://github.com/TheSlowlySnail/MT_Backend_Iventorysystem

这是我的服务:

    httpOptions = {
    headers: new HttpHeaders({
      /* 'Content-Type': 'application/json', */
      'X-Requested-With': 'XMLHttpRequest',
      'Content-Type': 'application/x-www-form-urlencoded'
    })
  };
  constructor(private http: HttpClient) { }

  signup(username: string, email: string, password: string, c_password: string) {
    return this.http.post('http://127.0.0.1:8000/api/userRegister', { name: username, email: email, password: password,
    c_password: c_password  },
      this.httpOptions).subscribe(
        respone => { console.log(respone); }
      );


  }

这是我的crontroller:

  constructor(private authService: AuthService) { }

  ngOnInit() {
  }

  onSignup(form: NgForm) {
    this.authService.signup(form.value.username, form.value.email, form.value.password, form.value.c_password);
  }

错误讯息:

无法加载http://127.0.0.1:8000/api/userRegister:预检的响应包含无效的HTTP状态代码500。

本教程的后端

https://itsolutionstuff.com/post/php-laravel-56-rest-api-with-passport-tutorialexample.html

我不知道如何继续。我也看过类似的问题,我也尝试了很多。不幸的是没有成功。

1 个答案:

答案 0 :(得分:-1)

这是一个CORS问题,您必须在Laravel应用程序中启用访问权限。

看看This question,其中包含了这一点。

相关问题