使用PHP的cURL做POST網路請求。
private function requestByCurl($input) {
try {
$apiUrl = "{https://your_request_url}";
$postData = array(
"category" => 1,
"store_name" => "テスト_",
"store_id" => 123
"timestamp" => time(),
);
$header = array(
'Content-Type: application/json',
'Authorization: JWT '.self::API_KEY
);
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_POST, true); // POST
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$errorNo = curl_errno($ch);
log_message("debug", "post data:".print_r(json_encode($postData), true));
log_message("debug", "info:".print_r($info, true));
log_message("debug", "response:".print_r($response, true));
curl_close($ch);
} catch (Exception $e) {
log_message("error", $e->getMessage());
}
}
Laravel8+Vue3+Bootstrap5實作TODO List ep09:安裝bootstrap5並美化todo list畫面
Laravel8+Vue3+Bootstrap5實作TODO List ep07:安裝vue3跟基本設定
Laravel8+Vue3+Bootstrap5實作TODO List ep08:用vue重新製作todo list畫面
Laravel8+Vue3+Bootstrap5實作TODO List ep06:初步認識Web Route
Laravel8+Vue3+Bootstrap5實作TODO List ep05:製作新增、更新、刪除待辦事項的API