【发布时间】:2020-05-29 10:30:45
【问题描述】:
我尝试将此 curl 命令(proxmox api)转换为 php curl:curl -k -b "PVEAuthCookie=PVE:root@pam:4EEC61E2::rsKoApxDTLYPn6H3NNT6iP2mv..." https://10.0.0.1:8006/api2/json/
我使用网站https://incarnate.github.io/curl-to-php/进行转换,但它不支持“-b”标签。
经过一番搜索,我尝试了这段代码:
<?php
$apiurlvmName = "https://10.0.0.1:8006/api2/json/";
$proxmoxid = "username=root@pam&password=mypass";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurlvmName);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $proxmoxid);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIE, "PVEAuthCookie=PVE:root@pam:4EEC61E2::rsKoApxDTLYPn6H3NNT6iP2mv...");
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
else {
echo $result;
}
curl_close($ch);
?>
但它不起作用。该页面需要几秒钟才能加载,然后我得到一个没有显示错误的空白页面。好像"curl_setopt($ch, CURLOPT_COOKIE, "PVEAuthCookie=PVE:root@pam:4EEC61E2::rsKoApxDTLYPn6H3NNT6iP2mv...");" 还不够。
我错过了什么吗?如何将 curl "-b" 标签正确转换为 php ?谢谢。
【问题讨论】:
-
这个问题应该被标记为重复,解决方案已经存在请看stackoverflow.com/questions/16872082/…