简体   繁体   中英

How to call API using curl in php

I have developed some API using laravel and created a virtual host on my local machine. like abc.xyz.com/api/v1/oauth2/token for getting oauth token. Now I want to test these API
from another local app say abc.com using curl.

I am not getting any response .How can I do this ?Where both apps are in my local machine.

Curl will give you a lot of trouble to do many things, use Guzzle to consume your API. It's simple, it has it all figured out and it works:

Install

composer require "guzzlehttp/guzzle" "~4.0"

Create a client:

$client = new \GuzzleHttp\Client();

Get results:

$response = $client->get('http://abc.example.com/api/v1/oauth2/token');

dd($response->getBody());

Project: https://github.com/guzzle/guzzle

I got the answer for my question myself. Actually I forgot to add / at the end of URL that why is was not giving any response .

Thanks to All for Help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM