0

When i call API of my software i get all POST parameters NULL.

Class and function call:

class THBS_AUTH_API
{
    private const API_USER = $API_USER;
    private const API_PASS = $API_PASS;

    public static function CMD_AUTH($CMD = null, $GET_STATUS = 0, $ADDITIONAL_PARAMETERS = null)
    {
        $base_url = $_SERVER['SERVER_NAME'];
        $fields = array(
            'API_USER' => urlencode(self::API_USER),
            'API_PASS' => urlencode(self::API_PASS),
            'TOKEN' => urlencode(self::API_USER),
            'CMD' => urlencode($CMD),
            'FROM' => urlencode("From https://website.com"),
            'ADDITIONAL_PARAMETERS' => urlencode($ADDITIONAL_PARAMETERS)
        );

        $fields_string = '';
        //url-ify the data for the POST
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string, '&');

        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL, "http://apiexample.com/API/private/THBS-API.php");
        curl_setopt($ch,CURLOPT_POST, true);
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


        //execute post
        $result = curl_exec($ch);

        //close connection
        curl_close($ch);

        $response = json_decode($result, true);
        if($GET_STATUS == 0) { return $response['response_data']; }
        else { return $response['response_status']; }
    }
}
echo THBS_AUTH_API::CMD_AUTH("DEBUG_ALL", 1);

I can't figure out why i have this problem, all post data is not sent.

problem is from cUrl 100%

Please help me.

Thos-Host
  • 67
  • 9
  • 2
    if curl was not working, it would have made the news by now. More likely you are misusing an api. What does `curl_getinfo` tell you, http status code, etc.... It aint woiking is no description for a problem. – YvesLeBorg Feb 08 '20 at 22:42
  • 1
    Does this answer your question? [PHP - Debugging Curl](https://stackoverflow.com/questions/3757071/php-debugging-curl) – ArSeN Feb 08 '20 at 22:47
  • hmm, looks like i have same response even if i put a random link, i deleted cache and is same. – Thos-Host Feb 09 '20 at 10:30

0 Answers0