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 check if multiple inputs are empty 
Php :: get site url 
Php :: php logout 
Php :: laravel faker example 
Php :: where is phpinfo() 
Php :: laravel update all relations 
Php :: laravel log reader 
Php :: taxonomy_get_parents drupal 8 
Php :: wp_list_pluck 
Php :: min function in php 
Php :: how naming resource routes laravel 
Php :: laravel logger 
Php :: how to enable pretty url in yii2 
Php :: ubuntu apache php version 
Php :: wpml get site url 
Php :: php sprintf 
Php :: Termlaravel validation exists array data 
Php :: json to html php table 
Php :: function passing multiple arguments using 3 dots php 
Php :: Access-Control-Allow-Origin php laravel 
Php :: drupal 7 hook_node_update 
Php :: post loop 
Php :: insertion sort in php 
Php :: laravel foreach loop index in controller 
Php :: laravel image store 
Php :: joomla get group id 
Php :: mysqli exception handling 
Php :: database seeder laravel 
Php :: echo in console command laravel 
Php :: laravel Auth::logoutOtherDevices 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =