我一直在研究一个可用于内部wiki的脚本,它将删除非活动用户的属性。我相信我几乎在那里但是api有问题。
我想我需要在$ delete路径上使用 urlencode 但仅限于电子邮件地址中的@和属性中的#。我知道如何使用urlencode来完成整个过程,但不仅仅是这样。它的工作方式是循环获取属性,其中大部分包含名称中的#。任何能够帮助修改以使其有效的人都将非常感激!
这是脚本:
<?php
$user_id="john_smith@ourwiki.com";
$url=('http://admin:12345@192.168.245.133/@api/deki/users/=john_smith@ourwiki.com/properties');
$xmlString=file_get_contents($url);
$delete = "http://admin:12345@192.168.245.133/@api/deki/DELETE:users/$user_id/properties/%s";
$xml = new SimpleXMLElement($xmlString);
function curl_fetch($url,$username,$password,$method='DELETE')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // returns output as a string instead of echoing it
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password"); // if your server requires basic auth do this
return curl_exec($ch);
}
foreach($xml->property as $property) {
$name = $property['name']; // the name is stored in the attribute
curl_fetch(sprintf($delete, $name),'admin','12345');
}
?>
答案 0 :(得分:0)
喜欢这个吗?
$delete = "http://admin:12345@192.168.245.133/@api/deki/DELETE:users/".urlencode($user_id)."/properties/%s";