我有一個前端代碼捲曲操作和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));
}
,我有捲曲時,解僱其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」}
=================== ================================================== ====================
的基本功能
-------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"}
我試過了,但沒有運氣。 – lilzz
你可以發佈你的服務器的Header響應,對於那個特定的文件,確保它不壓縮它或需要HTTP認證! – adrian7