【问题标题】:Guzzle ServerException resulted in a `500 Internal Server Error` responseGuzzle ServerException 导致“500 Internal Server Error”响应
【发布时间】:2018-04-18 10:00:20
【问题描述】:

我正在尝试使用 Lumen 和 laravel 实现一个微服务架构

我使用 laravel 5.4 作为 ApiGetway,使用 Lumen 5.4 作为微服务

我在我的 laravel 项目中使用 GuzzleHTTP 6.3 版,试图访问微服务 API,但我收到 500 内部服务器错误

我正在我的本地主机中尝试这个

这就是我提出请求的方式:

public function get_posts(){
    try {

       $client = new Client(); //GuzzleHttp\Client
       $res = $client->request('GET', 'http://localhost/micro/posts_micro_service/public/posts');
         if($res->getStatusCode() == "200"){
             echo $res->getBody();
         }else{
             return response()->json(['status',"error"]);
         }
     } catch (ClientException $e) {
            echo Psr7\str($e->getRequest());
            echo Psr7\str($e->getResponse());
    }
}

我收到此错误:

 (1/1) ServerException
Server error: `GET http://localhost/micro/posts_micro_service/public/posts` resulted in a `500 Internal Server Error` response:
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
(truncated...)
in RequestException.php (line 113)

【问题讨论】:

    标签: php laravel-5 microservices guzzle lumen


    【解决方案1】:

    使用新端口运行 php 服务器
    例如:-

    对于 Laravel:

    php -S localhost:8000 -t public
    

    对于流明:

    php -S localhost:8001 -t public
    

    它对我有用。使用此方法而不是设置 vhost。

    【讨论】:

      【解决方案2】:

      问题是因为 Lumen 和 Laravel 使用相同的机器并共享相同的环境,所以当我调用环境变量时,它们被覆盖了。

      【讨论】:

      • 那么你想出的解决方案是什么
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 2022-07-25
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多