Curlの書き方について、教えて頂きたいです。
下の cURL を実行したときと同じようにPostされるコードを書きたいです。
以下のコードを作成しましたが、$this->log(print_r($res, true), LOG_DEBUG); での出力結果を見ると以下のエラーが出ます。
どの部分に間違いがあるでしょうか。
■cURL
curl -X POST https://asia-northeast1-dev-project.cloudfunctions.net/delete_file_dev
-H "Content-Type:application/json"
-d '{"id":"1234","ac_code":"1234"}'
■Post内容
id:1234
ac_code:1234
■記述したコード
public function admin_del() { $ch = curl_init(); $data = ['id' => '1234','code' => '1234']; $apiUrl = 'https://asia-northeast1-dev-project.cloudfunctions.net/delete_file_dev' $options = array( CURLOPT_URL => $apiUrl, CURLOPT_HEADER => array('Content-type: application/json'), CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $POST, CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, ); curl_setopt_array($ch, $options); $res = curl_exec($ch); curl_close($ch); $this->log(print_r($res, true), LOG_DEBUG); //$resの中身を確認 return $res; }
■$resの中身
2020-06-17 15:02:21 Debug: HTTP/1.0 400 Bad Request Content-Length: 54 Content-Type: text/html; charset=UTF-8 Date: Wed, 17 Jun 2020 06:02:21 GMT <html><title>Error 400 (Bad Request)!!1</title></html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。