【问题标题】:Get TOKEN auth2 - POST client data - bad request获取令牌 oauth2 - POST 客户端数据 - 错误请求
【发布时间】:2019-09-06 08:34:07
【问题描述】:

在我的 react APP 中使用令牌 API 时出现问题(404:错误请求)。 在 Post man 中,它工作得很好

  const requestOptions = {
            method: 'POST',
            mode: "no-cors", // no-cors, cors, *same-origin
            cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
            credentials: "include", // include, *same-origin, omit
            redirect: "follow", // manual, *follow, error
            referrer: "no-referrer", // no-referrer, *client
            headers: {
            },
            body: JSON.stringify({
                "client_id": "1_15dpzlnknhtwk8sgo4gwo800okogc4g00gk4k04g4g0cgc0ww0",
                "client_secret": "dc86f30rr6okw8w84c8owkcko08s4k8k4c4c4k04osow8skko",
                "grant_type": "password",
                "username": "demoUsername",
                "password": "demoPassword"
            })
        };

fetch('http://localhost:8000/oauth/v2/token', requestOptions)
    .then(function(response) {
        console.log('response');
        console.log(response);

    })
    .then(function(myJson) {
        console.log(JSON.stringify(myJson));
    });

结果是:

这是我的 security.yml

【问题讨论】:

  • 你可以访问构建api的symfony项目吗?如果 awnser 是,执行 php bin/console debug:route 并检查列表中是否出现“oauth/v2/token”
  • 是的,在我的本地主机中 - 我可以用 postMan 测试它并且工作得很好
  • fos_oauth_server_token GET|POST ANY ANY /oauth/v2/token
  • 您是否尝试将正文作为对象而不是字符串发送?
  • 是的,总是 - 404 错误 - 请求

标签: reactjs api symfony fosrestbundle


【解决方案1】:

是header的问题,header是空的 现在开始工作了

【讨论】:

    猜你喜欢
    • 2017-08-22
    • 2015-05-11
    • 2016-06-22
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    相关资源
    最近更新 更多