cURL request in Laravel

前端 未结 5 1328
梦如初夏
梦如初夏 2021-01-30 23:44

I am struggling to make this cURL request in Laravel

curl -d \'{\"key1\":\"value1\", \"key2\":\"value2\"}\' -H \"Content-Type: application/json\"   -X GET http:/         


        
5条回答
  •  無奈伤痛
    2021-01-31 00:07

    You can still use the native cURL in PHP if you have trouble using guzzlehttp:

    Native Php way

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "SOME_URL_HERE".$method_request);
    // SSL important
    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);
    

    Sometimes this solution still better and simplier than using the library attached in the Laravel framework. But still your choice since you hold the development of your project.

提交回复
热议问题