You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

cUrl in controller

Accepted answer
30
Views
3
Comments
edited Jun 7, 2022 1:21PM in General Technical Discussions 3 comments

Content

Hi,

I'm trying to test some cUrl functionality. I'm using the code mentioned but I get:

There has been an error with your request.

However, accessing the controller directly, it runs fine. The reason I am testing cUrl is what I want to put it into the custom scripts section of a report so the function is run on a schedule.

I am using the exact same cUrl syntax for requests to the REST API without issue so why is it failing here?

Code Snippet

public function testcurlhere() {

    RNCPHP\ConnectAPI::getCurrentContext()->ApplicationContext = "Get Google Places API";
    $url = "https://{SITE_NAME}.custhelp.com/cc/{CONTROLLER_NAME}/{FUNCTION_NAME}";

    if (!function_exists("\curl_init")){
        \load_curl();
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT,6000);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
    $body = \curl_exec($ch);
    curl_close($ch);
    var_dump($body);

}

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!