简体   繁体   English

PHP cURL 返回空白页

[英]PHP cURL return blank page

I had been using PHP curl to get the contents of a file, hosted on a different server.我一直在使用 PHP curl 来获取托管在不同服务器上的文件的内容。 The file can easily be opened on a browser like Chrome etc., but with cURL, it always returns a blank page.该文件可以在 Chrome 等浏览器上轻松打开,但使用 cURL,它总是返回空白页。

The file is hosted on an Nginx server and even miniproxy.php fails to get contents.该文件托管在 Nginx 服务器上,甚至 miniproxy.php 也无法获取内容。 Instead, it returns 406 not acceptable.相反,它返回 406 不可接受。 I tried using the HTTP spy extension to monitor the request sent and found the following header:我尝试使用 HTTP 间谍扩展来监视发送的请求,发现以下 header:

Upgrade-Insecure-Requests:1 I tried sending the same header along With other headers, but in vain. Upgrade-Insecure-Requests:1我尝试将相同的 header 与其他标头一起发送,但徒劳无功。 Still, I couldn't rectify my mistake.尽管如此,我还是无法纠正我的错误。 On the Internet, I found the zalmos proxy which was able to get the contents of the file.在 Internet 上,我找到了能够获取文件内容的 zalmos 代理。 The curl code I wrote is attached below.我写的curl代码附在下面。

$url = "http://smumcdnems01.cdnsrv.jio.com/jiotv.live.cdn.jio.com/" . $ch . "/" . $ch . "_" . $q  . ".m3u8" . $tok;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "User-Agent: agent",
   "lbcookie: 300",
   "devicetype: 1",
   "os: android",
   "appkey: 1111111",
   "deviceId: device id",
   "uniqueId: unique id",
   "ssotoken: any token",
   "Upgrade-Insecure-Requests: 1",
   "Host: example.com",
   "Connection: keep-alive",
   "X-Chrome-offline: persist=0 reason=reload",
   "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
   "Accept-Encoding: gzip, deflate, sdch",
   "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8",
   "subscriberId: any id",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
echo $url;
echo $resp;

I believe that any part is missing in my code which is posing a problem.我相信我的代码中缺少任何构成问题的部分。 How can this be rectified?如何纠正?

Check your URL.检查您的 URL。 Curl must give you the response. Curl 必须给您答复。 If it's hit the target URL, either the target URL is not responding to anything when sending the request.如果它命中目标 URL,则目标 URL 在发送请求时没有响应任何内容。

You may be trying to access a websocket.您可能正在尝试访问 websocket。 Try to simulate with Postman to get more information.尝试使用Postman进行模拟以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM