PHP cURL HTTP PUT [英] PHP cURL HTTP PUT

查看:149
本文介绍了PHP cURL HTTP PUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用cURL创建一个HTTP PUT请求,我不能让它工作。我读了很多教程,但没有一个实际工作。这是我目前的代码:

I am trying to create a HTTP PUT request with cURL and I can't make it work. I've read many tutorials but none of them actually worked. Here's my current code:

$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但得到相同的结果。问题是存储库说没有设置元数据。我真的需要帮助!谢谢!

I've also tried using PHP PEAR but got the same result. The problem is that the repository says that no metadata has been set. I really need help! Thanks!

推荐答案

今天刚刚做过...这里是我为我工作的代码...

Just been doing that myself today... here is code I have working for me...

$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

这篇关于PHP cURL HTTP PUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆