0
我試圖使用REST API和PHP7
95%肯定,我需要這樣的使用PHP7和捲曲通過API
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
的要求,但我總是創造詹金斯工作創造詹金斯工作諸如「無法保存config.xml」和「內容在prolog中不被允許」之類的錯誤。我的猜測是,問題出現是因爲我沒有使用--data-binary param
我只是無法弄清楚如何在php 7中使用「new CurlFile
爲了理解,這裏是我的代碼:
$url = static::$host.'/job/'.$folderName.'/createItem?name='.$jobname;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, Array('file' => new CurlFile($xmlConfigurationFile)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, static::$user.":".static::$pass);
$headers = array('Content-Type: text/xml');
if ($jenkins->areCrumbsEnabled()){
$headers[] = $jenkins->getCrumbHeader();
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
在$ xmlConfigurationFile是將文件
路徑還存在具有權威性,CSRF,創建文件夾或文件路徑沒有問題
所以,問題是:
我怎樣才能發送XML文件中的二進制通過curl在php7中?
在此先感謝
你有沒有想過使用PHP Jenkins的圖書館? [包裝](https://packagist.org/search/?q=jenkins)上似乎有一些。 – StephenKing