dsiy62758 2019-01-12 07:44
浏览 556

GuzzleHttp导致在存在的路线上找不到404

I am sending request to POST api.myserver.com/v1/oauth/token to get a token with client_credentials as follows:

$client = new GuzzleHttp\Client; // A guzzle client
$response = $this->client->post('http://api.myserver.com/v1/oauth/token', [
  'form_params' => [
    'grant_type' => 'client_credentials',
    'client_id' => 'MY_CLIENT_ID',
    'client_secret' => 'MY_CLIENT_SECRET',
    'scope' => ''
  ],
  'headers' => [
    'Accept' => 'application/json'
  ]
));

I am using apiato framework so the default laravel passport token generating routes have been modified to something like api.myserver.com/v1/oauth/token and hence the path.

Now the code above is throwing a 404 not found exception when I run it from the browser. It's working fine when I run it on POSTman. And also it works fine when I run it in the test environment.

Client error: `POST http://api.myserver.com/v1/oauth/token` resulted in a `404 Not Found` response:
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" co (truncated...)

I tried changing the path to http://myserver.com/oauth/token with no luck. What could be going wrong?

  • 写回答

1条回答 默认 最新

  • donglei2022 2019-01-12 08:31
    关注

    Well, the reason you're getting 404 when you try to reach this endpoint using the browser is because it is a POST request. When you reach a URL via browser it is a GET request.

    评论

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao