PHP cURL GET request and request's body

前端 未结 5 1282
礼貌的吻别
礼貌的吻别 2020-12-05 00:23

i\'m trying using cURL for a GET request like this:

function connect($id_user){
    $ch = curl_init();
    $headers = array(
    \'Accept: application/json\'         


        
5条回答
  •  死守一世寂寞
    2020-12-05 00:48

    For those coming to this with similar problems, this request library allows you to make external http requests seemlessly within your php application. Simplified GET, POST, PATCH, DELETE and PUT requests.

    A sample request would be as below

    use Libraries\Request;
    
    $data = [
      'samplekey' => 'value',
      'otherkey' => 'othervalue'
    ];
    
    $headers = [
      'Content-Type' => 'application/json',
      'Content-Length' => sizeof($data)
    ];
    
    $response = Request::post('https://example.com', $data, $headers);
    // the $response variable contains response from the request
    

    Documentation for the same can be found in the project's README.md

提交回复
热议问题