$client = new GuzzleHttpClient;
$response = $client->get('https://api.example.com/api/AvailabilitySearch', [
'headers' => [
'Authorization' => 'Bearer YOUR_TOKEN_HERE',
],
'form_params' => [
'VisitDate' => '2017-05-08',
'PartySize' => '2',
'ChannelCode' => 'ONLINE',
],
]);
// You need to parse the response body
// This will parse it into an array
$response = json_decode($response->getBody(), true);
/////////////////////////////////////////////////////
$endpoint = "http://my.domain.com/test.php";
$client = new GuzzleHttpClient();
$id = 5;
$value = "ABC";
$response = $client->request('GET', $endpoint, ['query' => [
'key1' => $id,
'key2' => $value,
]]);
// url will be: http://my.domain.com/test.php?key1=5&key2=ABC;
$statusCode = $response->getStatusCode();
$content = $response->getBody();
// or when your server returns json
// $content = json_decode($response->getBody(), true);
// we can still use native PHP curl, even in Laravel app )
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "SOME_URL_HERE".$method_request);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close($ch);
$this->response['response'] = json_decode($output);
$url="http://abc/api/xyz.php"; //url of 2nd website where data is to be send
$postdata = $data
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0)
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-Type', 'application/json'));
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
<?php
namespace AppHttpControllers;
use IlluminateSupportFacadesHttp;
class ITSController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$apiURL = 'https://api.mywebtuts.com/api/users';
$postInput = [
'first_name' => 'Hardik',
'last_name' => 'Savani',
'email' => 'example@gmail.com'
];
$headers = [
'X-header' => 'value'
];
$response = Http::withHeaders($headers)->post($apiURL, $postInput);
$statusCode = $response->status();
$responseBody = json_decode($response->getBody(), true);
dd($responseBody);
}
}