【问题标题】:Cannot execute API call to another Laravel website无法对另一个 Laravel 网站执行 API 调用
【发布时间】:2021-04-10 03:06:48
【问题描述】:

今天我试图用 Guzzle 对另一个服务执行 API 调用。 但问题是,如果我在本地向该服务发出请求,它就可以正常工作。 应该提到的是,当服务在 Modx 时,仍然会重现此类错误。目前服务已被 Laravel 应用取代。

但是当我从开发服务器发出请求时,如果失败并出现以下错误:

`GET http://example.com/api/v1/products?codes=1` resulted in a `415 Unsupported Media Type` response:


production.ERROR: #0 /home/..../vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/..../vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/.../vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)

file_get_contents() 返回相同的错误。当我在浏览器中打开链接时,它工作正常

谁能帮帮我?

【问题讨论】:

  • 错误信息明确指出你不能GET example.com/api/v1/products?codes=1 - 你可能有URL,但不是GET
  • 没有。如果我直接从浏览器请求而没有任何问题,它可以正常工作。此外,如果我使用相同的代码从本地环境请求它对于 example.com 工作正常
  • 好吧,那么您的浏览器和file_get_contents()call 之间的操作有所不同,因为这就是错误消息的内容。
  • 我有以下响应头:{"responseHeaders":{"Date":["Mon, 04 Jan 2021 10:43:42 GMT"],"Content-Type":["application /octet-stream"],"Transfer-Encoding":["chunked"],"Connection":["close"],"Server":["imunify360-webshield/1.13"]},"responseProtocol":"1.1 "}
  • @Vladislav 你能和Guzzle分享请求吗?

标签: php laravel http guzzle


【解决方案1】:

答案并不简单。 Imunify360 保护已安装在另一端并阻止来自我的服务器的呼叫。

【讨论】:

    猜你喜欢
    • 2017-10-15
    • 2021-03-05
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 2019-12-19
    • 2019-02-11
    相关资源
    最近更新 更多