2014-10-09 2 views
0

PHP 컬 호출을하려고합니다. 이 호출은 POSTMAN에서 작동하며 다음과 같이 표시됩니다.PHP 컬 호출을 통해 데이터 가져 오기

URL Endpoint: https://api.sb.example.com/v1/resource/identifier 

Headers: 
Content Type: application/json 
Authorization : Bearer AccessTokenValue 

HTTP Protocol : GET 

이 호출은 유효한 JSON 응답을 반환합니다. 이제 PHP를 사용하여 동일한 작업을 수행 할 때 응답을 얻을 수 없습니다. 여기 내 PHP 컬 호출은 다음과 같습니다

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://api.sb.example.com/v1/resource/identifier"); 
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, true); 

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type : application/json', 
              'Authorization : Bearer AccessTokenValue' 
)); 

$data = curl_exec($ch); 
print_r($data); 
curl_close($ch); 

PHP를 통해이 호출은 나에게 오류 제공 : 코드에 대한

HTTP/1.1 401 Unauthorized 
Server: Apache-Coyote/1.1 

모든 아이디어/제안? curl_exec 전에

답변

0

말했다 아래에 추가하십시오 라인()

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);           
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
0

그래서 나는 키 값 쌍의 헤더 배열의 공간을 가지고, 알아 냈어. 그것은

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 

을 했어야

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type : application/json', ..) 

관련 문제