Documentation

CURL

The CurlRequest class lets you make HTTP requests in PHP.

Requirements

In order to use PHP's cURL functions you need to install the ยป libcurl package.

Methods

  • CurlRequest::setEndpoint($endpoint)
    Set the endpoint where make HTTP request to the cUrl.
  • CurlRequest::setIsPost($isPost)
    The method accept boolean value (true or false) in case your request is in POST method otherwise set into FALSE.
  • CurlRequest::setReturnTransfer($returnTransfer)
    Set TRUE to return the raw output
  • CurlRequest::setGetFields($fields)
    Set the method Get with their $fields
  • CurlRequest::setPostFields($fields)
    Set the field with POST method, This parameter can be passed as an array with the field name as key and field data as value.
  • CurlRequest::setCustomHeader($data)
    The headers specified in this parameter will be used in requests both to servers and proxies. Like An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100').
  • CurlRequest::send()
    Execute cUrl request, and the return data can be obtained using Class MessageBag.
    The result if the cUrl request have success can be obtained by using method getData.
    In case of error you can check the existing of error using method hasError and getErrorMessage

Example

    $request = new CurlRequest();
    $request->setEndpoint(Config::get("url")."/api/getLogList");
    $request->setPostFields(json_encode(array(
        'input' => "s",
        'model' => "w"
    )));
    $request->setContentTypeJSON(true);
    $mb = $request->send();