douyan3478 2015-12-25 06:55
浏览 394

Lumen API + Laravel guzzlehttp响应500内部服务器错误

I am working on a Lumen + Laravel application wherein Lumen is my RESTful API while my Laravel is the web app itself.

Laravel 5.2.0

Lumen 5.1.6

I have installed guzzlehttp on my Laravel web app for API requests (get, post, delete, put). Whenever I do a GET request, I get a Server error: 'GET http://example.local/api/blog' resulted in a '500 Internal Server Error' response: when retrieving from my Lumen API. But when I do a request thru PostMan, I am able to retrieve data successfully even when I input http://example.local/api/blog directly on the browser, I get the json response.

Lumen GET:

public function getBlogs()
{
    return response()->json($this->sqlConnection()->table(self::TABLE_NAME)->get(), 200);
}

Laravel:

public function index(Client $client)
{
    return $client->get('http://example.local/api/blog')->getBody();
}

I do have other RESTful APIs build with a different framework and tried to test it out if my Laravel web app could connect and it was able to. I find it weird because connecting thru my Lumen API always return a 500 internal server error.

  • 写回答

1条回答 默认 最新

  • dongyuxiao6295 2015-12-25 07:36
    关注

    So after hours of debugging, I finally found the answer. On the .env file, there seems to be a conflict with these lines:

    DB_HOST=localhost
    DB_DATABASE=homestead
    DB_USERNAME=homestead
    DB_PASSWORD=secret
    

    I removed those on my Laravel web app and I am now able to get a response from my Lumen API!!! (Hooray!) But I wonder, does anybody knows why Laravel is getting those environment variables? I am not encountering any problem when those lines are on while my API is NOT a Lumen framework. It just happens when my API is Lumen. Seems weird to me that Laravel is using those variables.

    Also, why do my Lumen API shares or gets value from my Laravel .env file?

    Lumen .env:

    API_USERNAME=lumentest
    API_PASSWORD=lumenpassword
    

    Laravel .env:

    API_USERNAME=laraveltest
    API_PASSWORD=laravelpassword
    

    Whenever my Laravel makes a request on my Lumen, it gets the API_USERNAME and API_PASSWORD from my laravel app instead on the Lumen.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line