Client portal

How to make cURL requests from inside a plugin?

 October 13, 2014     0 Comments

Don't use cURL functions directly. Instead use our provided curlRequest function, which abstracts the choosing between the cURL extension and the cURL binary file if set by the administrator. Also you'll have the request's request and response logged at level 5.

Here's the prototype:

curlRequest(str url, str request, array headers, bool insecure, bool simulatedBrowser)
Only the first argument is mandatory.
- url: URL and any GET vars you want: e.g www.foo.com?bar=foobar
- request: POST payload. Used in the option CURLOPT_POSTFIELDS
- headers: used in the option CURLOPT_HTTPHEADER
- insecure (defaults to false): when making SSL connections through https, it bypasses certificates checks on both the client and server. Sets CURLOPT_SSL_VERIFYHOST to 0 and CURLOPT_SSL_VERIFYPEER to false. People usually set this argument to true to make it work in most servers...
- simulatedBrowser (defaults to false): set to true if you want to send a User-Agent and Connection:close headers. Most people don't need this.


The function returns the response string, or the Error_CE object in case something went wrong.

How helpful was this article to you?

Posting has been disabled.