在 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 请求了。