2013-08-29 3 views
5

file_get_contents은 오류가 발생해도 실제 응답을 표시 할 수 있습니까?file_get_contents : 오류가 발생해도 전체 응답 받기

그렇지 않으면 디버그하기가 어렵습니다. 예를 들어, 다음과 같은 코드가 있다고 가정 :

$url = 'https://api.twitter.com/oauth/request_token'; 
$data = array(); 

$options = array(
    'http' => array(
    'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
    'method' => 'POST', 
    'content' => http_build_query($data), 
    ), 
); 
$context = stream_context_create($options); 
$result = @file_get_contents($url, false, $context); 

var_dump($result); 
var_dump($http_response_header); 

이는 결과와 HTTP 헤더의 날 NULL 보여줍니다,하지만 난 (Failed to validate oauth signature and token 같은 것을해야한다) 트위터가 다시 보내는 실제 메시지를 얻으려면, 어떤이다 브라우저에 https://api.twitter.com/oauth/request_token을로드하려고하면 어떻게됩니까?

답변

5

컨텍스트에 대해 아주 간단한 스위치가 있습니다. ,

'ignore_errors' => true 

그래서 당신이

$options = array(
    'http' => array(
    'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
    'method' => 'POST', 
    'content' => http_build_query($data), 
    'ignore_errors' => true 
    ) 
); 
+0

최고 얻을 것이다이 같은 스위치의 어떤 종류가 있었다 기대했다 : 단지 옵션이 줄을 추가합니다. – houbysoft

관련 문제