简体   繁体   中英

cURL request is getting NULL response from imgur api

    $image = file_get_contents($_FILES['upload']['tmp_name']);
    $id = 'myid';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Client-ID ' . $id));
    curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => base64_encode($image) ));
    $response = curl_exec($ch);
    curl_close($ch);
    $response = json_decode($response);

this is the block of quote that i have to make anonymous image uploads to imgur. it works on xampp on my mac os machine, but it is not working on xampp on my windows. i also know the following about curl on windows xampp:

-it is enabled
-it works when i try to grab the content of an url
-it doesnt work when i try to make DELETE request to remove an anonymous image(the same code works on the mac os xampp)

i figured there are some differences between the cURL settings on the two computers. i would appreciate it if you can show me the ways! thanks in advance.

That's an SSL issue. Please try the following line before the curl_exec call

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

(And you might add var_dump($response); to see the server response.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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