나는 프론트 엔드 코드컬 운영 및 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는 백엔드 코드에 의한 API 구문 분석 이전에도 성공한 200을 얻었습니다. 나는 후 상태 = 200 JSON 응답 기대 { "상태": "OK", "데이터": "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
서버의 헤더 응답을 게시 할 수 있습니까? 특정 파일에 대해 압축하지 않거나 HTTP Auth가 필요합니다! – adrian7