У меня есть код интерфейса
$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 ) );
}
и у меня есть бэкэнд-код, который выполнялся, когда cURL запускал свою работу со своим URL. Следовательно, код бэкэнда будет активирован. Итак, я знаю, что cURL работает.
$output=array (
'status'=>'OK',
'data'=>'12345'
)
$output=json_encode($output)
echo $output;
и $output
отображаются в браузере как {"status":"OK","data":"12345"}
Однако я вернулся к коду внешнего интерфейса и сделал echo $responseJSON
, я ничего не получил. Я думал, что вывод {"status":"OK","data":"12345"}
пойдет на $responseJSON
. есть идеи?
Вот вывод в Браузере, что-то очень странное! response_status получил 200, что является успехом даже до анализа API бэкэнд-кодом. Я ожидаю, что status = 200 и ответ json после {"status": "OK", "data": "12345"}
=============================================== ==========================================
внутри get API основных функций
-------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"}