[英]CURL with PHP to Azure
如何使用 PHP 創建一個工作項 CURL:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://dev.azure.com/fernandodomenike/fernando/_apis/wit/workitems/$Task?api-version=5.1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
'file' => '@' .realpath('azure.json')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'secret');
$headers = array();
$headers[] = 'Content-Type: application/json-patch+json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
我嘗試使用命令行 Windows 執行並開始工作。
我怎么了?
通過@上傳文件是命令行 cURL 客戶端的一項功能,您必須在 PHP 上實現自己的代碼才能執行此操作。
例子:
$json = file_get_contents('azure.json');
// Attach JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
我希望它能幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.