I am trying to update a user field using restws. It doesn't return any error, but doesn't update the content either. The code snippet is given below.

$url = "DRUPAL_ROOT/user/1.xml";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "restws_user" . ":" . "password");
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("status"=>"0")));
curl_setopt($ch, CURLOPT_HTTPHEADER,array (
"Content-Type: text/xml",
"Accept: text/xml"
));

$retValue = curl_exec($ch);
var_dump($retValue);
curl_close($ch);

The dump of $retValue returns huge string with complete user info.!

I can't spot any errors in the code, still it is unable to perform the operation.

Comments

programmer153’s picture

Status: Active » Closed (fixed)
programmer153’s picture

The issue is fixed by passing "Content-Type: application/json" header and sending json encoded data.