PHP curl HTTP PUT

我正在尝试使用cURL创build一个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梨,但得到了相同的结果。 问题是存储库说没有设置元数据。 我真的需要帮助! 谢谢!

我自己今天就这样做了…这是我为我工作的代码…

 $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/putting-data-fields-with-php-curl