无法获取某些POST数据,而其他则是[重复]

问题描述 投票:-1回答:1

一个简单的问题,为什么我的API没有得到$_POST['TOKEN']$_POST['API_USER']$_POST['API_PASS']

其余数据都可以。

class THBS_AUTH_API
{
    public static function CMD_AUTH($CMD = null, $GET_STATUS = 0, $ADDITIONAL_PARAMETERS = null)
    {
        $base_url = $_SERVER['SERVER_NAME'];
        $token = $API_USER;
        $fields = array(
            'API_USER' => urlencode($API_USER),
            'API_PASS' => urlencode($API_PASS),
            'TOKEN' => urlencode($token),
            'CMD' => urlencode($CMD),
            'FROM' => urlencode("https://".$base_url."/API/endsoftware.php"),
            '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, "https://thos-host.com/API/private/THBS-API.php");
        curl_setopt($ch,CURLOPT_POST, true);
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
        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']; }
    }
}

使用(IN API)简单调试:

$str = LICENSE_API::GET_DATA("getToken", 0 , $_POST['FROM'])."|".$_POST['TOKEN']."|".$_POST['CMD']."|".$_POST['API_USER']."|".$_POST['API_PASS']."|".$_POST['FROM'];
            response($str);

[$_POST['TOKEN']$_POST['API_USER']$_POST['API_PASS']是空字符串,为什么?

php api curl post
1个回答
-1
投票

CMD_AUTH函数内部似乎没有得到$API_USER$API_PASS,所以它们为空。

© www.soinside.com 2019 - 2024. All rights reserved.