2014-10-10 2 views
0

콘텐츠를 가져 오는 URL에서 X-AUTH 인증을 사용할 때 file_get_contents을 사용하는 데 문제가 있습니다. X-AUTH 토큰을 가지고 있지만 실제로는 file_get_contents에 묶는 방법을 잘 모르겠습니다. 이 결과 브라우저의 페이지를 방문 할 때 오류가 발생합니다. 그 중 일부는 다음과 같습니다.X-Auth를 사용하여 file_get_contents

경고 : 스트림을 열지 못했습니다 : HTTP 요청이 실패했습니다! HTTP/1.1 401 Unauthorized

나는 X-AUTH와 함께 사용하지 않으므로 file_get_contents와 많은 거래를 한 적이 한번도 없었습니다.

도움을 주시면 감사하겠습니다.

감사

+0

:

Using Authentication And file_get_contents()

블로그 항목이 이것을 달성하는 방법에 대한 좋은 예를 포함 file_get_contents()'이렇게하려면 대신 여기를보십시오. http://stackoverflow.com/questions/13187462/sending-auth-in-headers-php-curl – Crontab

답변

1

foloowing 블로그 게시물을 읽어 보시기 바랍니다 : 당신이`사용할 수 있습니다 의심

$username = 'username'; 
$password = 'password'; 

$context = stream_context_create(array(
    'http' => array(
     'header' => "Authorization: Basic " . base64_encode("$username:$password") 
    ) 
)); 
$data = file_get_contents($url, false, $context);