laravel curl – How To Make cURL HTTP Request Example

laravel curl, laravel curl request example, using curl in laravel 8 example, laravel 8 curl request, laravel 8 curl post request example. Laravel CURL Request Example using ixudra/curl.

in many time you need to integrate any third party APIs in your laravel application.

laravel curl

Custom PHP cURL library for the Laravel 8 or 9 framework. you can done this with cURL or HTTP guzzle request. cURL is a command-line tool for getting or sending data including files using URL syntax.

you can done this with cURL or HTTP guzzle request.

Laravel 8 cURL HTTP Request Example

GET Request Example :

$my_ch = curl_init();

curl_setopt_array($my_ch, array(
    CURLOPT_URL => "https://www.pakainfo.com",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_TIMEOUT => 30000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json',
    ),
));
$response = curl_exec($my_ch);
$display_user_error = curl_error($my_ch);
curl_close($my_ch);

if ($display_user_error) {
    echo "cURL Error #:" . $display_user_error;
} else {
    print_r(json_decode($response));
}

POST Request Example :

$data = [
    'name' => 'pakainfo',
    'email' => '[email protected]',
];

$my_ch = curl_init();

curl_setopt_array($my_ch, array(
    CURLOPT_URL => "https://www.pakainfo.com",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($data),
    CURLOPT_HTTPHEADER => array(
        "accept: */*",
        "accept-language: en-US,en;q=0.8",
        "content-type: application/json",
    ),
));

$response = curl_exec($my_ch);
$display_user_error = curl_error($my_ch);

curl_close($my_ch);

if ($display_user_error) {
    echo "Sorry, cURL Error #:" . $display_user_error;
} else {
    print_r(json_decode($response));
}

Don’t Miss : Laravel curl POST request

I hope you get an idea about laravel curl.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment