Answers for "laravel send http post request"

PHP
3

laravel send post request from controller

use Illuminate\Support\Facades\Http;

$response = Http::post('http://example.com/users', [
    'name' => 'Steve',
    'role' => 'Network Administrator',
]);

// By default, data will be sent using the application/json content type
Posted by: Guest on February-26-2021
0

laravel send http post request json

use GuzzleHttp\Client;
class yourController extends Controller {

    public function saveApiData()
    {
        $client = new Client();
        $res = $client->request('POST', 'https://url_to_the_api', [
            'form_params' => [
                'client_id' => 'test_id',
                'secret' => 'test_secret',
            ]
        ]);
        echo $res->getStatusCode();
        // 200
        echo $res->getHeader('content-type');
        // 'application/json; charset=utf8'
        echo $res->getBody();
        // {"type":"User"...'
}
Posted by: Guest on December-21-2020

Code answers related to "laravel send http post request"

Browse Popular Code Answers by Language