使用JavaScript和Angular(HttpClient)进行FPL Api身份验证

时间:2019-12-18 01:39:22

标签: javascript angular api xmlhttprequest

我正在尝试使用FPL API进行身份验证 谁能在下面帮助我,我找不到错误的地方

这是身份验证指南https://medium.com/@bram.vanherle1/fantasy-premier-league-api-authentication-guide-2f7aeb2382e4

我收到此错误

  

状态:200

     

statusText:“确定”

     

url:   “ https://cors-anywhere.herokuapp.com/https://users.premierleague.com/accounts/login/

     

好:错误

     

名称:“ HttpErrorResponse”

     

消息:“解析过程中的Http失败   https://cors-anywhere.herokuapp.com/https://users.premierleague.com/accounts/login/


import { HttpClient } from '@angular/common/http';




constructor(private http: HttpClient) {}



getData() {


    const proxy = 'https://cors-anywhere.herokuapp.com/';

    this.http
      .post(${proxy}https://users.premierleague.com/accounts/login/,
   {
      redirect_uri: 'https://fantasy.premierleague.com/a/login',
      app: 'plfpl-web',
      login: 'my-email',
      password: 'may-pass'
    }
)
      .subscribe((data) => {
        console.log(data);
      });
  }
}

1 个答案:

答案 0 :(得分:0)

如果您访问为请求指定的URL,它将告诉您确切的问题:

缺少必需的请求标头。必须指定以下项之一:origin,x-requested-with