cURL request in Laravel

前端 未结 5 1370
梦如初夏
梦如初夏 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

    Using Laravel, you can write something like this in your routes file if your are using WP and you are feeling adventurous and don't want to use guzzle or laravel curl package.

    Route::get('/curl',function() {
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, 'https://example.net/wp-login.php');
    
    // save cookies to 'public/cookie.txt' you can change this later.
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, ['log'=>'','pwd'=>'']);
    
    curl_exec($ch);
    
    // supply cookie with request
    curl_setopt($ch, CURLOPT_COOKIE, 'cookie.txt');
    
    // the url you would like to visit
    curl_setopt($ch, CURLOPT_URL, 'https://example.net/profile/');
    
    $content = curl_exec($ch);
    
    curl_close($ch);
    
    // webpage will be displayed in your browser
    return;
    
    });
    

提交回复
热议问题