Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel curl request

$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);
Comment

laravel curl package

// 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);
Comment

curl in laravel

$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);
Comment

curl post laravel

<?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);

    }

}
Comment

PREVIOUS NEXT
Code Example
Php :: php mkdir 
Php :: Laravel - Comparison betweeon two column values - whereColumn 
Php :: carbon last day of month in timestamp 
Php :: php closecursor 
Php :: aravel 8 how to order by using eloquent orm 
Php :: php difference between two dates 
Php :: laravel route slug 
Php :: php count amount of times a value appears in array 
Php :: laravel log daily 
Php :: laravel sort by numbers 
Php :: remove array element php 
Php :: max_execution_time php 
Php :: invalid datetime format 1292 
Php :: php syntax 
Php :: laravel seed 
Php :: append file in php 
Php :: php curl asyc 
Php :: time to string in php 
Php :: calculate sum (total) of column in php 
Php :: how to use php echo data in javascript 
Php :: laravel custom attributes 
Php :: https redirect in htacess for php laravel 
Php :: use ternary operator as null coalescing operator in php 
Php :: get woocommerce order details 
Php :: How to validate a file type in laravel 
Php :: php error reporting 
Php :: Deleting an element from an array in PHP 
Php :: random digit with seed php 
Php :: get all category custom post type wordpress dev 
Php :: guzzlehttp form data 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =