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();

Share this article:

If this resonates with you I'd love to help!

I help business with problems like these every day.

Click below to schedule a call.

About The Author

Bryce Hamrick

Facebook Twitter

Bryce Hamrick is an entrepreneur, business & marketing strategist, and product consultant with nearly two decades of experience in industry. Bryce has been a software engineer, product manager, and director of product management for startups as well as large enterprises. He has led teams to bring dozens of products to market and has executed numerous six-figure product launches. Today Bryce and his team focus on leveraging his product execution strategy to help businesses with growth and scale.