我正在使用PHP 5.3.6,而且似乎無法使用CURL爲PUTting字符串創建PUT請求。在PHP中使用CURL編寫PUT請求
function put_data($url, $data)
{
$useragent="SimpleAgent-1.0";
$fh = fopen('php://memory', 'rw');
fwrite($fh, $data);
rewind($fh);$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
fclose($fh);
return $result;
}
在這裏,$ data是我想要PUT的字符串。 不工作,返回以下錯誤:
500 Internal Server Error The server has either erred or is incapable of performing the requested operation.
expected string or buffer
你的PHP有'error_log'嗎? – alex 2012-02-08 08:13:04
嘗試關閉倒帶前($ fh);無論如何閱讀apache日誌 – ZiTAL 2012-02-08 08:13:17
倒回後($ fh); – ZiTAL 2012-02-08 08:37:58