在 PHP 中實現 PUT 請求可以通過以下步驟:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api/resource');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('key1' => 'value1', 'key2' => 'value2')));
$result = curl_exec($ch);
curl_close($ch);
完整示例代碼如下:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api/resource');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('key1' => 'value1', 'key2' => 'value2')));
$result = curl_exec($ch);
curl_close($ch);
這樣就可以在 PHP 中實現 PUT 請求了。