vBulletin vB_vURL class

There’s a seemingly undocumented class in vB4 called vB_vURL that auto-detects server support for cURL / fsockopen when performing an HTTP request – it’s used in the native API client class. I’m using it in a plugin I’m developing at the moment and decided to share my findings.

It’s structured like a standard cURL client, with the following constants defined to be used with the ‘set_option’ method:

VURL_URL
VURL_TIMEOUT
VURL_POST
VURL_HEADER
VURL_POSTFIELDS
VURL_ENCODING
VURL_USERAGENT
VURL_RETURNTRANSFER
VURL_HTTPHEADER
VURL_CLOSECONNECTION
VURL_FOLLOWLOCATION
VURL_MAXREDIRS
VURL_NOBODY
VURL_CUSTOMREQUEST
VURL_MAXSIZE
VURL_DIEONMAXSIZE
VURL_VALIDSSLONLY
VURL_ERROR_MAXSIZE
VURL_ERROR_SSL
VURL_ERROR_URL
VURL_ERROR_NOLIB
VURL_HANDLED
VURL_NEXT
VURL_STATE_HEADERS
VURL_STATE_LOCATION
VURL_STATE_BODY

Here’s an example of how to use it:

$postparams = array("var1" => "value1", "var2" => "value2");
$vurl = new vB_vURL($vbulletin);
$vurl->set_option(VURL_HEADER, false);
$vurl->set_option(VURL_RETURNTRANSFER, true);
$vurl->set_option(VURL_CLOSECONNECTION, true);
$vurl->set_option(VURL_POST, 1);
$vurl->set_option(VURL_POSTFIELDS, http_build_query($postparams, '', '&'));
$vurl->set_option(VURL_URL, "http://example.com/api/");
$results = $vurl->exec();