Bonjour,



Je ne parviens pas à obtenir les données d'une base de données distante en json, j'obtiens un "plain text" malgré ce code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
 
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Content-Type: application/json");
header("Access-Control-Allow-Methods:  GET, POST, PATCH, PUT, DELETE, OPTIONS");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
//header('Content-Type: text/html; charset=utf-8');
 
$data = urlencode('SELECT Nom, Prenom, email FROM clients');
 
 
$url='https:xxxxxxxxdata='.$data;
 
$ch = curl_init($url);
$data = array(
	'nom' => 'nom',
	'prenom' => 'prenom',
	'email' => 'email'
);
 
$data_json = json_encode(array("customers" => $data));
 
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
$res = curl_exec($ch);
$err = curl_error($ch);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
// echo $contentType;
 
curl_close($ch);
 
if ($err) {
  echo "cURL Error #:" . $err;
}
 
else {
    echo $res;
}

Le resultat me renvoie un "text/plain" - string de type :



Nom Prenom email
SURxxx JEAN-BAPTISTE xxxxxxxxxxxxxx
PINxxx LAURENT xxxxxxxxxxxxxx
EXCxxx EVELYNE xxxxxxxxxxxxxx



Merci d'avance !