【问题标题】:API responding with 500 through browser, but works with PostmanAPI 通过浏览器响应 500,但适用于 Postman
【发布时间】:2019-06-26 22:15:46
【问题描述】:

我正在构建一个使用 Angular 作为我的前端、PHP Slim 作为我的 API 和 Apache 的网站。我有一个特定的 post call,当通过 Postman 运行时,它可以工作,所以我在网站上实现了它,但它在那里返回 500,控制台中的错误如下:

POST (myurl) 500 (Internal Server Error)
Failed to load (myurl): No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '(my domain)' is therefore not allowed access. The response had HTTP status code 500.
Cross-Origin Read Blocking (CORB) blocked cross-origin response (myurl) with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

我似乎无法弄清楚为什么会发生这种情况,或者如何调试它。我认为这可能是 POST 调用的问题,但我的登录 POST 调用工作正常。我不知道它是完全是 Apache,还是来自 PHP。我有执行预检检查的代码:

return $response
    ->withHeader('Access-Control-Allow-Origin', env('FRONTEND_DOMAIN'))
    ->withHeader('Access-Control-Allow-Methods', implode(',', $methods))
    ->withHeader('Access-Control-Allow-Headers', '*');

所以标题应该没问题(其他调用正在工作)。

【问题讨论】:

  • 显示您提出的请求,确保您在标头中访问控制允许来源

标签: php apache slim


【解决方案1】:

您必须检查在邮递员中您没有禁用“SSL 证书验证”,如果它被停用,API 调用必须遵循此标准。 enter image description here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 2019-12-20
    • 2018-03-25
    • 1970-01-01
    • 2019-11-09
    相关资源
    最近更新 更多