Add extra cURL options in HttpTransport

The HttpFactory can be used to instantiate a transport driver. One of the drivers that can be used is cURL and is usually specified as first driver to use. cURL takes a number of options that can be set and how to add extra cURL options in HttpTransport is explained in this article.

Adding cURL options

Using HttpTransport you can make external calls as explained in the Making external calls using HttpFactory article

To add options to the cURL HttpTransport we need to supply it as an array. First we create the options array.

$curlOptions = [];

Now that we have an array we can fill it with the cURL options we want to set. A full list can be found on the curl_setopt website.

$curlOptions[CURLOPT_SSL_VERIFYHOST] = false;
$curlOptions[CURLOPT_SSL_VERIFYHOST] = false;

Now that we have set the options and values we want, we can pass it on to the HttpTransport. The options can be set by using the setOption() command and add the options to the transport.curl, value.

$http->setOption('transport.curl', $curlOptions);

Now the call to the external source can be made and the cURL options will be used.

Related Articles