0

Okay so this problem is bothering me quite a bit.

I've created a controller function in my CodeIgniter projects at [project_url]/admin/orderpicking/get_updated_statuses

function name: get_updated_statuses controller name: Orderpicking.php controller location: application/admin

Inside the controller all I have is

ob_start();
print_r('success');
file_put_contents('file.txt', ob_get_contents());
ob_end_clean();

to confirm that I am hitting the controller.

When I hit the controller directly from my browser, the file gets created with 'success' as the content.

When I use cURL from another project to hit the controller, nothing happens, the result is an empty string (I dont care about the result right now, but the file.txt file is no longer being created).

Code that calls the controller is as follows:

$data = array('datetime'=>new DateTime());
        $header = array(
            'Identification:Portal::ReadAPI', // TODO config
            'Content-Type:application/x-www-form-urlencode'
        );
        $url = '[local instance]/admin/orderpicking/get_updated_statuses'; // TODO config

        $curlGetUpdatedItems = curl_init($url);
        /** CURL OPTIONS */
        curl_setopt($curlGetUpdatedItems, CURLOPT_POST, 1);
        curl_setopt($curlGetUpdatedItems, CURLOPT_POSTFIELDS, json_encode(serialize($data)));
        curl_setopt($curlGetUpdatedItems, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curlGetUpdatedItems, CURLOPT_RETURNTRANSFER, true);
//        curl_setopt($curlGetUpdatedItems, CURLOPT_SSL_VERIFYPEER, true);
//        curl_setopt($curlGetUpdatedItems, CURLOPT_SSL_VERIFYHOST, 2);
//        curl_setopt($curlGetUpdatedItems, CURLOPT_CAINFO, $certificate_location);
        /** CURL OPTIONS */

        $result = curl_exec($curlGetUpdatedItems);

Are there any obvious mistakes I'm making here? I will add in a certificate later when I make the portal https but until then I don't think I need it?

Any help and/or advice is extremely welcome!

----- UPDATE -----

After var_dump'ing the result I've noticed that a boolean true is returned. curl_error($curlGetUpdatedItems) returns an empty string.

5
  • Where is this "other project"? localhost is not accessible from outside of your own PC. Do you have a local DNS entry set up so that other things can find your localhost? Commented Mar 14, 2017 at 14:17
  • From your "other project" try curl_error() Commented Mar 14, 2017 at 14:19
  • Do you have error reporting turned on everywhere? Have you checked your web server access logs? Commented Mar 14, 2017 at 14:20
  • @MonkeyZeus everything is currently local. Commented Mar 14, 2017 at 14:25
  • @MonkeyZeus I've updated my original post with more information regarding possible errors that could have occurred Commented Mar 14, 2017 at 14:25

1 Answer 1

1

you can do it make by steps:

$data_string = http_build_query($data);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($data));
curl_setopt($ch,CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

$result = json_decode($result,true);

don't know if need the header, i think that the default already is application/x-www-form-urlencode

id it not works, try changing the $data values in array. think helps . :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.