如何在phpcurl中请求这个

时间:2017-07-31 08:32:05

标签: php php-curl

$url = "http://ups.youku.com/ups/get.json?vid=XMTQ4ODM5Mjk2MA==&ct=10&ccode=0502&client_ip=0.0.0.0&utid=Ga3jEdWulXoCAXZwOs6IYOEY&client_ts=1501211617"

我尝试通过邮递员提出请求,添加一个标题(Referer:http://static.youku.com/),它有效。

但是当我使用CURL时,它总是没有显示任何内容。我不确定cookie是否会对此产生影响,因为我清除了chrome上的所有cookie,邮递员仍然有效。

我无法通过CURLOPT_COOKIEJARCURLOPT_COOKIEFILE为此请求获取有用的Cookie,任何机构都会帮助我,谢谢。

<?php
header("Content-type: text/html; charset=utf-8");
$headers = array(
    'Referer'    => 'http://static.youku.com/'
);

$url = 'http://ups.youku.com/ups/get.json?vid=XMTQ4ODM5Mjk2MA==&ct=10&ccode=0502&client_ip=0.0.0.0&utid=Ga3jEdWulXoCAXZwOs6IYOEY&client_ts=1501211617';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($curl);
curl_close($curl);


?>

1 个答案:

答案 0 :(得分:0)

对所有人来说,尝试将邮递员的参数添加到卷曲中,这种方式有效     

$curl = curl_init(); 

curl_setopt_array($curl, array( 
CURLOPT_URL => "http://ups.youku.com/ups/get.json?vid=XMTQ4ODM5Mjk2MA%3D%3D&ct=10&ccode=0502&client_ip=0.0.0.0&utid=Ga3jEdWulXoCAXZwOs6IYOEY&client_ts=1501211617", 
CURLOPT_RETURNTRANSFER => true, 
CURLOPT_ENCODING => "", 
CURLOPT_MAXREDIRS => 10, 
CURLOPT_TIMEOUT => 30, 
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
CURLOPT_CUSTOMREQUEST => "GET", 
CURLOPT_HTTPHEADER => array( 
"cache-control: no-cache", 
"postman-token: 88976d57-03fd-7950-6c65-9d0f191010dc", 
"referer: http://static.youku.com/"; 
), 
)); 

$response = curl_exec($curl); 
$err = curl_error($curl); 

curl_close($curl); 

if ($err) { 
echo "cURL Error #:" . $err; 
} else { 
echo $response; 
}