一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

在php腳本中使用curl

 印度阿三17 2019-07-05

我正在嘗試創(chuàng)建一個腳本,刪除特定個人的所有用戶屬性.我可以使用api調(diào)用來獲取用戶的屬性.我正在嘗試使用刪除api刪除每個屬性.但我有一個問題.以下是代碼:

$delete = "http://www./@api/DELETE:users/$user_id/properties/%s";
$xml = new SimpleXMLElement($xmlString);

foreach($xml->property as $property) {
  $name = $property['name']; // the name is stored in the attribute
  file_get_contents(sprintf($delete, $name));
}

我相信我需要使用curl來執(zhí)行實際刪除.以下是該命令的示例(property = something):

curl -u username:password -X DELETE -i http:///@api/users/=john_smith@/properties/something

-u提供外部用戶身份驗證.

-X指定HTTP請求方法.

-i輸出HTTP響應(yīng)頭.對調(diào)試很有用.

這是我可以合并到現(xiàn)有腳本中的東西嗎?或者我還需要做些什么嗎?任何幫助將不勝感激.

更新:

<?php

$user_id="john_smith@";

$url=('http://aaron:12345@192.168.245.133/@api/deki/users/=john_smith@/properties');
$xmlString=file_get_contents($url);

$delete = "http://aaron: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),'aaron','12345');
}

?>

解決方法:

您可以使用php curl,或使用exec外殼卷曲.

如果您的Web服務(wù)器上已經(jīng)啟用了curl,請使用php curl.如果你不能安裝php-curl復(fù)制curl的命令行版本,你很高興.

在php-curl中設(shè)置delete方法:

curl_setopt($ch,CURLOPT_CUSTOMREQUEST,’DELETE’);

編輯

像這樣的東西:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www./@api/whatever/url/you/want/or/need");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
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
$output = curl_exec($ch);

EDIT2

在函數(shù)中堅持上面的代碼:

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);
}

并使用新函數(shù)替換腳本中對file_get_contents()的調(diào)用.

curl_fetch(sprintf($delete,$name),’aaron’,’12345′);

完成.

來源:https://www./content-1-300351.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    久久少妇诱惑免费视频| 国产又大又黄又粗的黄色| 樱井知香黑人一区二区| 国产欧美日韩精品一区二| 1024你懂的在线视频| 亚洲中文字幕免费人妻| 日韩黄色一级片免费收看| 亚洲一区二区三区精选| 欧美区一区二在线播放| 日本高清中文精品在线不卡| 色综合久久六月婷婷中文字幕| 久久99精品国产麻豆婷婷洗澡| 国产黄色高清内射熟女视频| 国产传媒精品视频一区| 国产午夜在线精品视频| 亚洲国产精品久久网午夜| 国产乱淫av一区二区三区| 亚洲熟妇中文字幕五十路| 久久精品中文扫妇内射| 精品少妇人妻av免费看| 深夜日本福利在线观看| 日本最新不卡免费一区二区 | 精品熟女少妇一区二区三区| 精品一区二区三区乱码中文| 欧美一二三区高清不卡| 少妇丰满a一区二区三区| 欧美国产日本高清在线| 日韩欧美一区二区黄色| 免费人妻精品一区二区三区久久久| 欧美黄色黑人一区二区| 日韩精品一区二区三区含羞含羞草| 熟女一区二区三区国产| 东京热男人的天堂一二三区| 在线懂色一区二区三区精品| 日本加勒比在线观看一区| 亚洲一区二区精品国产av| 日韩精品小视频在线观看| 日韩人妻毛片中文字幕| 在线免费国产一区二区三区| 亚洲精品一区二区三区免| 国产人妻精品区一区二区三区 |