1
我一直在研究可用於內部wiki的腳本,該腳本將刪除處於非活動狀態的用戶的屬性。我相信我快到了,但是api有問題。在腳本中使用urlencode
我認爲我需要在$ delete路徑上使用urlencode但是隻能用於電子郵件地址中的@和屬性中的#號。我知道如何將urlencode用於整個事情,但不是那樣。它的工作方式是通過循環來獲取屬性,其中大部分都包含名稱中的#號。任何人可以幫助修改,以便這個作品將不勝感激!
下面是腳本:
<?php
$user_id="[email protected]";
$url=('http://admin:[email protected]/@api/deki/users/[email protected]/properties');
$xmlString=file_get_contents($url);
$delete = "http://admin:[email protected]/@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');
}
?>
此行是否有效?:'$ xmlString = file_get_contents($ url);'。如果是,則該URL有效。 – 2010-09-12 19:01:24
你不能只使用str_replace,如果你知道你想要編碼成什麼? – 2010-09-12 19:07:17
@SimpleCoder它確實存在,但問題是刪除api不起作用。當我使用urlencoded版本運行單獨的CURL命令時,它會根據需要刪除屬性。但是,當它沒有編碼時,它給了我一個404錯誤,無法完成。 – Aaron 2010-09-12 19:08:50