这是我的代码 - 为什么我会得到一个空白响应?
<?php
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_id = 'xxxxxxxxxxxxxxx';
$file = file_get_contents("test-image.png");
$url = 'https://api.imgur.com/3/image.json';
$headers = array('Authorization: Client-ID $client_id');
$pvars = array('image' => base64_encode($file));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL=> $url,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $pvars
));
$json_returned = curl_exec($curl); // blank response
echo "Result: " . $json_returned ;
curl_close ($curl);
?>
编辑:
一些 var_dump 结果:
var_dump(base64_encode($file)):
string iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAQAAAD2e2DtAADS7ElEQVR4Xu39B7SlaVbehz9fPDndnEPl0F2dw8z05CEjGIQAC2ELhABhIbAlZMmyhOEvB0mWg2zZQsaykJElkdMwwOTUM527qit0xVs353NPjl/6r/Vb77prCcYwDNM9A5pzV9UNJ33nffe7w7OfvbeV6A++xeZfwr+UM4hs85unP/m3r97+EAGIlcjip4SffSVK+LurPw23r97cP+z820YAJFsJXzY//8m+/TUnsEciWeeS9+oF/QPJ+qvJC3pS56wXk5+3Fm1XG/FsUnJ837LDKIhdO52Sx4GJO4OZ6L5txYtBEF7Udf1k/CdeA/zpv/0lu+THtu046SStiqZUiRK1kqS1Fu62c9NzltXYq3V7g6LizPhYuuSN24/GW14qmkliHaiehNbJeCGeSBwNrY6G1lF80719b/U3N2U/kXmxrVgak5KD+KsC8GXe6HXNas9KKSfpyC44l+yB'...
(length=72080)
var_dump($json_returned):
boolean false
编辑2:
print_r(curl_getinfo($curl)):
'( [url] => https://api.imgur.com/3/image.json [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.296 [namelookup_time] => 0.047 [connect_time] => 0.312 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 54.243.128.92 [primary_port] => 443 [local_ip] => 192.168.1.69 [local_port] => 4923 [redirect_url] => )'