The CurlRequest class within the Boostack\Models\Curl namespace is designed to facilitate the management and execution of cURL requests in PHP. It provides a series of methods that allow you to configure various aspects of the request, such as the endpoint URL, GET and POST fields, custom headers, request type (GET or POST), returning the transfer as a string, and the user agent. Once the necessary parameters are configured, the class allows you to send the request and obtain the response, thereby simplifying the interaction with external APIs or other web services.
In order to use PHP's cURL functions you need to install the ยป libcurl package.
$request = new CurlRequest(); $request->setEndpoint(Config::get("url")."/api/getLogList"); $request->setCustomHeader(array("Authorization: Bearer {[example api_key]}")); $request->setPostFields(json_encode(array( 'input' => $raw_content, 'model' => $model ))); $request->setContentTypeJSON(true); $mb = $request->send();
CurlRequest::setEndpoint($endpoint)
CurlRequest::setIsPost($isPost)
CurlRequest::setReturnTransfer($returnTransfer)
CurlRequest::setGetFields($fields)
CurlRequest::setPostFields($fields)
CurlRequest::setCustomHeader($data)
CurlRequest::send()
MessageBag
. getData
.hasError
and getErrorMessage