我正在尝试创建一个带有cURL的HTTP PUT请求,但我无法使其工作。我读过很多教程,但没有一个真正起作用。这是我当前的代码:
$filedata = array('metadata' => $rdfxml);
$ch = curl_init($url);
$header = "Content-Type: multipart/form-data; boundary='123456f'";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($filedata));
$returned = curl_exec($ch);
if (curl_error($ch))
{
print curl_error($ch);
}
else
{
print 'ret: ' .$returned;
}
我也尝试过使用PHP PEAR,但得到了同样的结果。问题是存储库说没有设置元数据。我真的需要帮助!谢谢!
我自己今天也这么做了...这是我为自己工作的代码...
$data = array("a" => $a);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
$response = curl_exec($ch);
if (!$response)
{
return false;
}
SRC:http://www.lornajane.net/posts/2009/put-data-fields-with-php-curl