Doing HTTP requests FROM Laravel to an external API

前端 未结 7 1675
隐瞒了意图╮
隐瞒了意图╮ 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:27

    You just want to call an external URL and use the results? PHP does this out of the box, if we're talking about a simple GET request to something serving JSON:

    $json = json_decode(file_get_contents('http://host.com/api/stuff/1'), true);
    

    If you want to do a post request, it's a little harder but there's loads of examples how to do this with curl.

    So I guess the question is; what exactly do you want?

    0 讨论(0)
提交回复
热议问题