我用php-curl发出请求,在响应中丢失了一些数据。(数据数组中填充了空对象,这里丢失了数据)
我的代码是:
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Connection: keep-alive', 'Accept: application/vnd.vimeo.video;version=3.4.1', 'Origin: https://vimeo.com', 'Authorization: jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Mzk0NzQ0NDAsInVzZXJfaWQiOjE1OTc1Nzk3NSwiYXBwX2lkIjo1ODQ3OSwic2NvcGVzIjoicHVibGljIHN0YXRzIHByaXZhdGUiLCJ0ZWFtX3VzZXJfaWQiOm51bGx9.6y_6aX_jChvbHpzK_72Y5SiHHrur44EEu1jh-1PZfn0', 'Sec-Fetch-Dest: empty', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36', 'Content-Type: application/json', 'Sec-Fetch-Site: same-site', 'Sec-Fetch-Mode: cors', 'Referer: https://vimeo.com/showcase/5694909?page=1', 'Accept-Language: en-US,en;q=0.9' $response = curl_exec($curl); print_r(curl_getinfo($curl)); curl_close($curl); echo $response;
这是输出:
curl_getinfo
Array ( [url] => https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass= [content_type] => application/vnd.vimeo.video+json [http_code] => 200 [header_size] => 1036 [request_size] => 1096 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.875052 [namelookup_time] => 0.000937 [connect_time] => 0.060644 [pretransfer_time] => 0.380411 [size_upload] => 0 [size_download] => 1401 [speed_download] => 1601 [speed_upload] => 0 [download_content_length] => 1401 [upload_content_length] => 0 [starttransfer_time] => 0.875005 [redirect_time] => 0 [redirect_url] => [primary_ip] => 151.101.64.217 [certinfo] => Array [primary_port] => 443 [local_ip] => 192.168.1.9 [local_port] => 59793 [http_version] => 2 [protocol] => 2 [ssl_verifyresult] => 0 [scheme] => HTTPS [appconnect_time_us] => 380306 [connect_time_us] => 60644 [namelookup_time_us] => 937 [pretransfer_time_us] => 380411 [redirect_time_us] => 0 [starttransfer_time_us] => 875005 [total_time_us] => 875052 )
回应:
{ "total": 76, "page": 1, "per_page": 12, "paging": { "next": "/albums/5694909/videos?page=2&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=", "previous": null, "first": "/albums/5694909/videos?page=1&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=", "last": "/albums/5694909/videos?page=7&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=" "data": [ ] }
请注意末尾的“数据”键中的空数组。
我在“邮递员”和“jQuery”中尝试了同样的请求。它返回正确的数据而不丢失任何数据。下面附加了Javascript。
var settings = { "url": "https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%2Cduration%2Cis_free%2Clive%2Cname%2Cpictures.sizes.link%2Cpictures.sizes.width%2Cpictures.uri%2Cprivacy.download%2Cprivacy.view%2Ctype%2Curi%2Cuser.link%2Cuser.name%2Cuser.pictures.sizes.link%2Cuser.pictures.sizes.width%2Cuser.uri&per_page=12&filter=&_hashed_pass=", "method": "GET", "timeout": 0, "headers": { "Connection": "keep-alive", "Accept": "application/vnd.vimeo.video;version=3.4.1", "Origin": "https://vimeo.com", "Authorization": "jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Mzk0NzQ0NDAsInVzZXJfaWQiOjE1OTc1Nzk3NSwiYXBwX2lkIjo1ODQ3OSwic2NvcGVzIjoicHVibGljIHN0YXRzIHByaXZhdGUiLCJ0ZWFtX3VzZXJfaWQiOm51bGx9.6y_6aX_jChvbHpzK_72Y5SiHHrur44EEu1jh-1PZfn0", "Sec-Fetch-Dest": "empty", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36", "Content-Type": "application/json", "Sec-Fetch-Site": "same-site", "Sec-Fetch-Mode": "cors", "Referer": "https://vimeo.com/showcase/5694909?page=1", "Accept-Language": "en-US,en;q=0.9"