0

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.

3
  • Maybe show some code, then we can take a look at your code and tell you whats wrong about your code or what a better solution is. And maybe a tip, use Guzzle Commented May 2, 2014 at 11:12
  • I always test first with Postman rest client. Commented May 2, 2014 at 11:18
  • $requestData = array( 'client_id' => 'test123', 'client_secret' => 'bPuD40fvL6eibi11i5iUH9T9jMR89p01', 'username' => '[email protected]', 'password' => 'somepassword', 'grant' => 'pass', ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => 'abc.example.com/api/v1/oauth2/token', CURLOPT_USERAGENT => 'OAuth Token Grant Request', CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $requestData, CURLOPT_SSL_VERIFYPEER=>false, CURLOPT_SSL_VERIFYHOST=>false )); $resp = curl_exec($curl); curl_close($curl); Commented May 2, 2014 at 11:20

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.