J'ai un code frontendopération cURL et PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_URL, $url);
//make the request
$responseJSON = curl_exec($ch);
$response_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response_status == 200) { // success
// remove any "problematic" characters from the json string and then decode
if (debug) {
echo "----finish API of getAPI inside basic_function with status==200---";
echo "<br>";
echo "-------the json response is-------" ; //.$responseJSON;
var_dump($responseJSON);
//print_r($responseJSON);
echo "<br>";
}
return json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $responseJSON));
}
et j'ai un code back-end qui a exécuté lorsque cURL a tiré son fonctionnement avec son URL. Le code backend serait donc activé. Donc, je sais que cURL fonctionne.
$output=array (
'status'=>'OK',
'data'=>'12345'
)
$output=json_encode($output)
echo $output;
et $output
affichés sur le navigateur comme {"status":"OK","data":"12345"}
Cependant, j'étais retourné au code frontend et a fait echo $responseJSON
, je n'ai rien. Je pensais que la sortie de {"status":"OK","data":"12345"}
serait allée au $responseJSON
. une idée?
Voici la sortie sur le navigateur, quelque chose est très étrange! le response_status a 200 qui est un succès avant même l'analyse de l'API par le code backend. Je pense état = 200 et la réponse JSON après la { "status": "OK", "data": "12345"}
=================== ============================================= ====================
dans l'API get des fonctions de base
-------url of cURL is -----http://localhost/test/api/session/login/?device_duid=website&UserName=joe&Password=1234&Submit=Submit
----finish API of getAPI inside basic_function with status==200---
-------the json response is-------string(1153)
"************inside Backend API.php******************
---command of api is--/session/login/
---first element of api is--UserName=joe
--second element of api is---Password=1234
---third element of api is----Submit=Submit
----fourth element of api is---
-------inside session login of api-------------
{"status":"OK","data":"12345"}
J'ai essayé, mais pas de chance. – lilzz
pouvez-vous poster la réponse en-tête de votre serveur, pour ce fichier spécifique, assurez-vous qu'il ne le compresse pas ou nécessite HTTP Auth! – adrian7