2016-07-15 6 views
1

간단한 GET 요청을 만들어 결과를 다시 얻으려고합니다. 나는 어떤 우두머리 또는 몸없이 우편 배달부에서 그것을 시도하고 잘 잘 작동한다. 나는 심지어 브라우저에 넣고 좋은 결과를 반환합니다. 하지만, PHP로 할 때 나는 아무것도 얻지 못하고있다. 이것이 내 코드의 모습입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?CURL을 사용하여 PHP에서 GET 요청을 수행하는 방법

 $curl = curl_init(); 

     curl_setopt($curl,CURLOPT_URL,'http://********/vizportal/api/web/v1/auth/kerberosLogin'); 
     curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($curl, CURLOPT_POST, 0); 
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, '20'); 

     $resp = curl_exec($curl); 

     echo $resp; 
+1

에 실패했습니다. curl_exec는 실패시 부울 false를 반환하며 길이가 0 인 문자열로 반향됩니다. try if ($ resp === false) {die (curl_error ($ curl)); }' –

+0

나는 에코 백을 얻지 못했고 간단한 JSON 응답을 기대하고있다. – anton2g

+0

거기에'var_dump (curl_error ($ curl));'를 추가하고 아무 것도 얻는 지보십시오. 또한 시간 초과를 문자열로 전달하는 이유는 무엇입니까? –

답변

0

사용이 헤더는 서버에 브라우저와 같은 헤더를 보내 : 당신은 그냥 아무것도 없다고 가정하고

$curl = curl_init('http://********/vizportal/api/web/v1/auth/kerberosLogin'); 
curl_setopt($curl, CURLOPT_POST, 0); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, '20'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
//  curl_setopt($curl, CURLOPT_HEADER, true); 
//  curl_setopt($curl, CURLINFO_HEADER_OUT, true); // enable tracking 

curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 
    'Accept-Encoding:gzip, deflate, sdch', 
    'Accept-Language:en-US,en;q=0.6', 
    'Cache-Control:max-age=0', 
    'Connection:keep-alive', 
    'Host:www.********.tld ', // for example : www.google.com 
    'Referer: http://********/vizportal/api/web/v1/auth/kerberosLogin', 
    'Upgrade-Insecure-Requests:1', 
    'User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36', 
)); 

$response = curl_exec($curl); 
curl_close($curl); 
+0

나는 이것을 작동시킬 수 없었다. HTTP/1.0 302 Found Location : https : // ********/vizportal/api/web/v1/auth/kerberosLogin 서버 : BigIP 연결 : Keep-Alive 콘텐츠 길이 : 0 – anton2g

+0

301 오류는 "Moved Permanently"을 의미합니다. 응답 헤더 [location : http://redirec-location.com/path/]에서 위치를 반환하도록 리디렉션해야합니다. - 새로운 위치로 컬 요청 보내기 - 응답 헤더를 사용하려면 추적 [이 줄의 끝 부분 주석] – Fadakar

관련 문제