简体   繁体   English

cURL请求正在从imgur API获取NULL响应

[英]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. 这是我必须将匿名图像上传到imgur的报价块。 it works on xampp on my mac os machine, but it is not working on xampp on my windows. 它可以在Mac OS机器上的xampp上运行,但不能在Windows上的xampp上运行。 i also know the following about curl on windows xampp: 我也知道以下有关Windows xampp上curl的信息:

-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. 我发现两台计算机上的cURL设置之间存在一些差异。 i would appreciate it if you can show me the ways! 如果您能向我展示方法,我将不胜感激! thanks in advance. 提前致谢。

That's an SSL issue. 这是一个SSL问题。 Please try the following line before the curl_exec call curl_exec调用之前,请尝试以下行

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

(And you might add var_dump($response); to see the server response.) (并且您可以添加var_dump($response);来查看服务器响应。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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