2011-10-09 4 views
0

나는 프론트 엔드 코드컬 운영 및 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"} 

답변

0

당신이 curl_setopt($ch, CURLOPT_TIMEOUT, 10);으로 시도 해 봤나 기본 기능의 가져 오기 API 내부

에게 댓글을 달았습니다? 해당 행에 주석을 달면 무슨 일이 일어나는 지보십시오. 또한

그건 당신이 나중에 추가 smthing, 작동하면, 기본 코드로 시도는 잘못된 것입니다 : false를 반환하는 경우

// create a new cURL resource 
$ch = curl_init(); 

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); 
curl_setopt($ch, CURLOPT_HEADER, false); 

// grab URL and pass it to the browser 
curl_exec($ch); 

// close cURL resource, and free up system resources 
curl_close($ch); 
+0

하지만 행운. – lilzz

+0

서버의 헤더 응답을 게시 할 수 있습니까? 특정 파일에 대해 압축하지 않거나 HTTP Auth가 필요합니다! – adrian7

0

해보십시오 위해서 var_dump ($ responseJSON)

시도

curl_error ($의 채널은)

마지막 컬 작업에 대한 일반 텍스트 오류 메시지를 반환합니다.

은 반드시 당신의 $ URL이 정확 있습니까?

내가 시도
+0

$ url은 정확합니다. 그렇지 않으면 백엔드 코드가이를 가로 채고 처리하지 않습니다. var_dump ($ responseJSON)는 문자열 (1153)을 반환합니다. curl_error ($ ch)는 ​​아무것도 반환하지 않습니다. – lilzz

+0

새로운 정보가 있으면 API 디버그 메시지가 활성화되어있는 것으로 생각합니다. 사용 중지/삭제하면 응답을받을 수 있습니다. – Quurks