AnsweredAssumed Answered

Sending data to an Entry Point

Question asked by David López on Mar 29, 2016

Hi,

 

I have been trying to send data to an EntryPoint via POST HTTP Request using CURL without success.

What I want is to call the URL of my EntryPoint using CURL and sending some data which that script would obtain using the $_POST parameters.

 

However when I do:

 

$data = array( 'test', 'test' );

$url = 'http://localhost/sugar/index.php?entryPoint=myEntryPoint'

$curl = curl_init();

curl_setopt( $curl, CURLOPT_URL, $url );

curl_setopt( $curl, CURLOPT_POST, count($data) );

curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $data ) );

curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );

$resp = curl_exec( $curl );

curl_close($curl);

 

in $resp I obtain an empty string ( "" ) and the script is never executed.

 

In the EntryPoint I get the POST parameters like this:

if( isset( $_POST['test'] ) {

     $param = $_POST['test'];

}

 

The EntryPoint is correctly created as I am able to execute it from the browser like this: http://localhost/sugar/index.php?entryPoint=myEntryPoint.

I have to say that I have been able to do this using a simple script instead of an EntryPoint, using the same code but changing the $url to this: 'http://localhost/sugar/index.php/my_script.php'; in this way everything works as expected.

 

Taking this into account, I suppose the problem is that the EntryPoint requieres authentication, as I created it like this:

$entry_point_registry['myEntryPoint'] = array(

     'file' => 'custom/scripts/myEntryPoint.php',

     'auth' => true

);

 

and of course the CURL HTTP Post Request does not put any header with any token nor the username and password to get authenticated to the server.

 

So, does anyone know how can I do this, or knows the header or something which I must put in the CURL Request in order to get the EntryPoint executed sending my own data?

 

NOTE: I want it to be done using POST; I know which I could do it sending the data in the URL like this: http://localhost/sugar/index.php?entryPoint=myEntryPoint&test=test

 

Thank you!

 

David

Outcomes