我有一个简单的GET请求,我正在尝试制作并获得结果。我已经在Postman中尝试了它,没有任何标题或正文,它工作得很好。我甚至把它放在我的浏览器中,它返回了一个很好的结果。但是,当我在PHP中使用它时,我没有得到任何东西。这就是我的代码。我做错了什么?
$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;
答案 0 :(得分: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);