Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
curl-xpost(php)_Php - Fatal编程技术网

curl-xpost(php)

curl-xpost(php),php,Php,我有下面的Curl命令。如何在PHP中执行此操作 curl -X POST "https://api.mystream.to/v1/remote-upload" -H "Authorization: ACCESS_TOKEN" -d "url=<URL>&path=<PATH?>" curl-X POST”https://api.mystream.to/v1/remote-upload" -H“授权:访问令牌” -d“url=&path=” 下面是PHP

我有下面的Curl命令。如何在PHP中执行此操作

curl -X POST "https://api.mystream.to/v1/remote-upload"
  -H "Authorization: ACCESS_TOKEN"
  -d "url=<URL>&path=<PATH?>"
curl-X POST”https://api.mystream.to/v1/remote-upload"
-H“授权:访问令牌”
-d“url=&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);
  • 执行命令并存储结果

    $result=curl\u exec($ch)


  • 检查以下网站,它将为您转换该代码。
    $headers[] = 'Authorization: ACCESS_TOKEN';
    $headers[] = 'Content-Type: application/x-www-form-urlencoded';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);