I have a clue on my curl request, when i'm passing a variable to the CURLOPT_URL parameter i get bad values from response, when i hardcode the url curl returns good values :
class APi {
public $this->url;
public $this->token; // :)
function __construct($url, $token){
$this->url = $url;
$this->token = $token;
}
function getUsers(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "4000",
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: 472244a4-af1d-4ca5-b26b-07f6b168c04b",
"x-access-token:" . $this->token
),));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r($response); //<== print bad values when CURLOPT_URL value is a variable
return $response;
}
}
} // end of class api
// Init the class
$data = new Api($url, $token);
print_r($data->getUsers());
the $this->url is initialised from the constructor, when i paste the value of $this->url to postman i get good results but from code i get bad results.
Someone can helps me ?
thank you.
====== SOLUTION ==========
From advices of some of you i have to urlencode individual parameter value, and it works as excepted. Thanks for the var_dump tip to compare characters length.