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 :: laravel duplicate row 
Php :: validation error laravel 8 with custom massage 
Php :: laravel 8 routes namespace 
Php :: Laravel Syntax error or access violation: 1071 Specified key was too long 
Php :: foreach reverse laravel 
Php :: change key value laravel map collection 
Php :: laravel session add 
Php :: laravel where json contains 
Php :: laravel unique column except self 
Php :: php upload file 
Php :: how to add sidebar to page.php 
Php :: How to remove updated_at or use only created_at laravel eloquent ORM 
Php :: symfony header token authorization 
Php :: wp_create_user 
Php :: $conn php 
Php :: php string slice 
Php :: get id by url wordpress 
Php :: install laravel in bootstrap 8 
Php :: laravel button redirect 
Php :: laravel 8 try catch 
Php :: web scraping in php 
Php :: php generating number 
Php :: how make custom menu in wordpress 
Php :: hello world in php 
Php :: adding days in datetime php 
Php :: laravel add attribute to model 
Php :: every wordpress page redirect to localhost ? 
Php :: remove empty array elements php 
Php :: add custom page to wordpress 
Php :: php calculate days of a month 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =