2016-08-25 20 views
0

cURLを使用してRESTapiにputリクエストを実行しようとしています。私はポストリクエストをすることができました。しかし、PUTはcURLを使用してREST APIにPUTリクエストを送信

が動作していない私は、次のコードを使用

public function callTeamworkPutApi($secretApiKey, $apiCallString,$param) 
{ 
     //cURL 
    $password = "xxx"; 
    $channel = curl_init(); 
    //options 

    curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/".$apiCallString); // projects.json?status=LATE gets all late projects 
    $headers = array(); 
    $headers[] = "Authorization: Basic " . base64_encode($secretApiKey . ":" . $password); 
    $headers[] = "Content-Type: application/json"; 
    curl_setopt($channel, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($channel, CURLOPT_PUT, true);                  
    //curl_setopt($channel, CURLOPT_POSTFIELDS, $comment); 
    curl_setopt($channel, CURLOPT_PUTFIELDS, $param); 
    // curl_setopt($channel, CURLOPT_RETURNTRANSFER, true); 


    $msg = curl_exec($channel); 
    $tester =var_dump(curl_getinfo($channel)); 
    curl_close($channel); 

    //var_dump($msg); 

    return response()->json(['res'=>$tester]); 


} 

エラー:

enter image description here

任意のアイデア?

答えて

1

今日は自分自身でやっています。ここにコード例があります。

$data = array("a" => $a); 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data)); 

$response = curl_exec($ch); 

if (!$response) 
{ 
    return false; 
} 

SRC:http://www.lornajane.net/posts/2009/putting-data-fields-with-php-curl

関連する問題