Doing HTTP requests FROM Laravel to an external API

前端 未结 7 1734
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 09:59

What I want is get an object from an API with a HTTP (eg, jQuery\'s AJAX) request to an external api. How do I start? I did research on Mr Google but I can\'t find anything

7条回答
  •  无人及你
    2020-11-27 10:26

    Based upon an answer of a similar question here: https://stackoverflow.com/a/22695523/1412268

    Take a look at Guzzle

    $client = new GuzzleHttp\Client();
    $res = $client->get('https://api.github.com/user', ['auth' =>  ['user', 'pass']]);
    echo $res->getStatusCode(); // 200
    echo $res->getBody(); // { "type": "User", ....
    

提交回复
热议问题