我有以下Curl命令。如何在PHP中执行此操作?
curl -X POST "https://api.mystream.to/v1/remote-upload"
-H "Authorization: ACCESS_TOKEN"
-d "url=<URL>&path=<PATH?>"
因此,以下是PHP代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mystream.to/v1/remote-upload');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "url=<URL>&path=<PATH?>");
$headers = array();
$headers[] = 'Authorization: ACCESS_TOKEN';
$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);
}
curl_close($ch);
所以我使用以下网站生成了这个:curl到PHP
现在,如果你想要更多的解释,就来吧。
设置URL
curl_setopt($ch, CURLOPT_URL, 'https://api.mystream.to/v1/remote-upload');
将身体设置为之前的状态
curl_setopt($ch, CURLOPT_POSTFIELDS, "url=<URL>&path=<PATH?>");
设置标头或您的访问令牌
$headers[] = 'Authorization: ACCESS_TOKEN'; $headers[] = 'Content-Type: application/x-www-form-urlencoded'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
执行命令并存储结果
$result = curl_exec($ch);