响应无法正常播放

时间:2019-03-27 16:22:56

标签: angular lumen

当我进行api调用时,我返回200,但响应返回html,并且在控制台中得到的错误是解析http://moviereview.test/moviereview/api/v1/public/login?email=conor@testing.com&password=name时的Http失败”响应是json格式的,有人可以告诉我为什么也正在发生,我知道在URL中张贴密码的做法很糟糕,我只是想让响应正常工作,然后解决在邮递员中运行它时遇到的任何安全问题,它将它作为JSON返回

/*Login Component*/
onSubmit() {
  this.api.login(this.user.email, this.user.password).subscribe(
    data => {
        this.user = data;
        localStorage.setItem('currentUser', JSON.stringify(this.user));
    });
 }
}
/*Login Service*/
  login(email: string, password: string) {
                const httpOptions = {
                  headers: new HttpHeaders({
                    'Content-Type':  'application/json'
                  })
                };
                return this.http.post<any>(this.env.LOCAL_ENDPOINT + '/login?email=' + email + '&password=' + password, httpOptions);
            }

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:3)

您正在传递HttpOptions作为请求中的主体。 http客户端上的post方法的第二个参数是请求正文。对于登录,您应该使用发布方法,并在请求正文中传递电子邮件和密码,如下所示:

/*Login Service*/
login(email: string, password: string) {
            const requestBody = {
                email: email,
                password: password
            };
            const httpOptions = {
              headers: new HttpHeaders({
                'Content-Type':  'application/json'
              })
            };
            return this.http.post<any>(this.env.LOCAL_ENDPOINT + '/login', requestBody, httpOptions);
        }