Curl请求在本地主机上工作,但不在线



当我在本地主机上使用curl和PHP发送请求时,它获得了成功,如下所示

这个请求是在本地主机上,并得到我需要的输出

$url = "https://live12p.hotstar.com/hls/live/2024725/ipl2021/hin/1540008470/15mindvrm01c6817544da534447ba5b5f3760666fd923september2021/master_7.m3u8";
$referer = "https://www.hotstar.com/";
$origin = "https://www.hotstar.com";
$host = "live12p.hotstar.com";
$headers   = array();
$headers[] = 'Host: ' . $host;
$headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0';
$headers[] = 'Cookie: hs_uid=5221b879-8857-496d-80bd-691646c0fcae; ajs_anonymous_id=%22e1cac957-8325-4cc5-a4c7-04c9322a50b5%22; ajs_user_id=%22971450d482ae40088b5d834ff952f60b%22; ajs_group_id=null; hdntl=exp=1632448848~acl=*ipl2021*~id=5267bf12e30107702f21c2ea2bf8b874~data=ip%3dwzSX5TdVuh1sa432PD6kIOuXAlfHJY32Vve29D3csZOD8xO2AjRrZpV-userid%3d8kP6OEf3LRYFUhAWTlF2R7ooxuElWlYpTzzEAosrFQCW-did%3dYfixYiH5EvZpALjGAYAzylXejGbgnbBi0BBLUmB93Jgj3HHJzJjbH16-~hmac=3508bd69101ca28bef6b9bb4ff4fb833c344404e3d62968cb38bcabb1d756a71';
$headers[] = 'Referer: ' . $referer;
$headers[] = 'Origin: ' . $origin;

// 

$response = get_web_page($url);
echo $response;
function get_web_page($url)
{
global $referer;
global $headers;
$ch = curl_init($url);
$verbose = fopen('curl.txt', 'w+');
$options = array(
CURLOPT_REFERER => $referer,   
CURLOPT_HTTPHEADER => $headers,  
CURLOPT_RETURNTRANSFER => true,   
CURLOPT_ENCODING       => "gzip, deflate, br", 
CURLOPT_USERAGENT      => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0",
CURLOPT_CONNECTTIMEOUT => 120, 
CURLOPT_TIMEOUT        => 120, 
CURLOPT_SSL_VERIFYPEER    => true,   
CURLOPT_SSL_VERIFYHOST    => 2,    
CURLOPT_VERBOSE    => TRUE,
CURLOPT_STDERR    => $verbose,   
);
curl_setopt_array($ch, $options);
$content  = curl_exec($ch);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:n<pre>", htmlspecialchars($verboseLog), "</pre>n";

if (curl_errno($ch)) {
// this would be your first hint that something went wrong
die('Couldn't send request: ' . curl_error($ch));
} else {
// check the HTTP status code of the request
$resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($resultStatus != 200) {
die('Request failed: HTTP status code: ' . $resultStatus);
}
}
curl_close($ch);
return $content;
}

这次的输出是我想要的

*   Trying 2600:140f:5800::17d7:d73a...
* TCP_NODELAY set
* Connected to live12p.hotstar.com (2600:140f:5800::17d7:d73a) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /Applications/XAMPP/xamppfiles/share/curl/curl-ca-bundle.crt
CApath: none
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=IN; ST=Maharashtra; L=Mumbai; O=Novi Digital Entertainment Pvt. Ltd.; CN=*.hotstar.com
*  start date: Jul  5 00:00:00 2021 GMT
*  expire date: Jul 13 23:59:59 2022 GMT
*  subjectAltName: host "live12p.hotstar.com" matched cert's "*.hotstar.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
*  SSL certificate verify ok.
> GET /hls/live/2024725/ipl2021/hin/1540008470/15mindvrm01c6817544da534447ba5b5f3760666fd923september2021/master_7.m3u8 HTTP/1.1
Host: live12p.hotstar.com
Accept: */*
Accept-Encoding: gzip, deflate, br
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Firefox/91.0
Cookie: hs_uid=5221b879-8857-496d-80bd-691646c0fcae; ajs_anonymous_id=%22e1cac957-8325-4cc5-a4c7-04c9322a50b5%22; ajs_user_id=%22971450d482ae40088b5d834ff952f60b%22; ajs_group_id=null; hdntl=exp=1632448848~acl=*ipl2021*~id=5267bf12e30107702f21c2ea2bf8b874~data=ip%3dwzSX5TdVuh1sa432PD6kIOuXAlfHJY32Vve29D3csZOD8xO2AjRrZpV-userid%3d8kP6OEf3LRYFUhAWTlF2R7ooxuElWlYpTzzEAosrFQCW-did%3dYfixYiH5EvZpALjGAYAzylXejGbgnbBi0BBLUmB93Jgj3HHJzJjbH16-~hmac=3508bd69101ca28bef6b9bb4ff4fb833c344404e3d62968cb38bcabb1d756a71
Referer: https://www.hotstar.com/
Origin: https://www.hotstar.com
< HTTP/1.1 200 OK
< Akamai-Path-Timestamp: i=1632413538.914;xi=1632413538.921;xo=1632413540.009;s=1632413540.017;
< Content-Encoding: gzip
< Content-Length: 1898
< Last-Modified: Thu, 23 Sep 2021 16:12:18 GMT
< X-Akamai-Live-Origin-QoS: d=4000;t=1632413538.918
< X-Akamai-Server: Akamai-SMT
< Vary: Accept-Encoding
< Akamai-Mon-Iucid-Ing: 2024725
< Expires: Thu, 23 Sep 2021 16:12:21 GMT
< Cache-Control: max-age=0, no-cache, no-store
< Pragma: no-cache
< Date: Thu, 23 Sep 2021 16:12:21 GMT
< Connection: keep-alive
< Content-Type: application/x-mpegURL
< Access-Control-Allow-Origin: https://www.hotstar.com
< Access-Control-Max-Age: 86400
< Access-Control-Allow-Credentials: true
< Access-Control-Expose-Headers: Server,range,hdntl,hdnts,Akamai-Mon-Iucid-Ing,Akamai-Mon-Iucid-Del,X-Reference-Error,X-ErrorType
< Access-Control-Allow-Headers: origin,range,hdntl,hdnts,X-allowRequest
< Access-Control-Allow-Methods: GET,POST,OPTIONS

但是这次当我从www.xyz.com在线发送这个请求时,输出是403 Forbidden为什么?

Verbose information:
* Added hotstar.com:2600:140f:5800::17d7:d73a to DNS cache
*   Trying 23.37.230.73:443...
* Connected to live12p.hotstar.com (23.37.230.73) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=IN; ST=Maharashtra; L=Mumbai; O=Novi Digital Entertainment Pvt. Ltd.; CN=*.hotstar.com
*  start date: Jul  5 00:00:00 2021 GMT
*  expire date: Jul 13 23:59:59 2022 GMT
*  subjectAltName: host "live12p.hotstar.com" matched cert's "*.hotstar.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
*  SSL certificate verify ok.
> GET /hls/live/2024725/ipl2021/hin/1540008470/15mindvrm01c6817544da534447ba5b5f3760666fd923september2021/master_7.m3u8 HTTP/1.1
Host: live12p.hotstar.com
Accept: */*
Cookie: hs_uid=5221b879-8857-496d-80bd-691646c0fcae; ajs_anonymous_id=%22e1cac957-8325-4cc5-a4c7-04c9322a50b5%22; ajs_user_id=%22971450d482ae40088b5d834ff952f60b%22; ajs_group_id=null; hdntl=exp=1632451493~acl=*ipl2021*~id=e1acc4c006ec4a10fb2422774e4b9806~data=ip%3dwzSX5TdVuh1sa432PD6kIOuXAlfHJY32Vve29D3csZOD8xO2AjRrZpV-userid%3d8kP6OEf3LRYFUhAWTlF2R7ooxuElWlYpTzzEAosrFQCW-did%3dYfixYiH5EvZpALjGAYAzylXejGbgnbBi0BBLUmB93Jgj3HHJzJjbH16-~hmac=c9248d2c8ea8b9e0420ad176918a1ea25561bab8af14b444594515491d00fb6e
Referer: https://www.hotstar.com/
Origin: https://www.hotstar.com
X-FORWARDED-FOR: 223.190.135.254
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Server: AkamaiGHost
< Mime-Version: 1.0
< Content-Type: text/html
< Content-Length: 416
< X-Reference-Error: 18.45e62517.1632413497.90e1a77
< Expires: Thu, 23 Sep 2021 16:11:37 GMT
< Cache-Control: max-age=0, no-cache, no-store
< Pragma: no-cache
< Date: Thu, 23 Sep 2021 16:11:37 GMT
< Connection: keep-alive
< Country: IN
< X-ErrorType: geo-blocked
< Access-Control-Allow-Origin: https://www.hotstar.com
< Access-Control-Max-Age: 86400
< Access-Control-Allow-Credentials: true
< Access-Control-Expose-Headers: Server,range,hdntl,hdnts,Akamai-Mon-Iucid-Ing,Akamai-Mon-Iucid-Del,X-Reference-Error,X-ErrorType
< Access-Control-Allow-Headers: origin,range,hdntl,hdnts,X-allowRequest
< Access-Control-Allow-Methods: GET,POST,OPTIONS
< 
* Connection #0 to host live12p.hotstar.com left intact
Request failed: HTTP status code: 403

我不知道为什么会发生这种情况,我该如何解决它如果有人有想法,请帮助我解决这个问题

您试图访问的服务位于Akamai的网络后面,看来他们正在地理上限制访问。

注意响应头:X-ErrorType: geo-blocked