簡體   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);

這是我必須將匿名圖像上傳到imgur的報價塊。 它可以在Mac OS機器上的xampp上運行,但不能在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)

我發現兩台計算機上的cURL設置之間存在一些差異。 如果您能向我展示方法,我將不勝感激! 提前致謝。

這是一個SSL問題。 curl_exec調用之前,請嘗試以下行

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

(並且您可以添加var_dump($response);來查看服務器響應。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM