[英]Run Curl command to the Linux Server via php
I need to run the curl command to the Linux Wowza server and here is my Curl command which needs to be executed on the remote machine. 我需要对Linux Wowza服务器运行curl命令,这是我的Curl命令,需要在远程计算机上执行。
curl -X PUT --header 'Accept:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/mystream/actions/restart --digest -u "user:password"
here is my converted curl to the php 这是我转换为PHP的curl
<?php
$url = 'http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/mystream/actions/restart';
$username = 'user';
$pass = 'password';
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_URL, "$url");
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERNAME, "$username");
curl_setopt($ch, CURLOPT_PASSWORD, "$password")
curl_close ($ch);
?>
Any Tip will be helpful for me to figure this out. 任何提示将有助于我弄清楚这一点。 thanks in advance
提前致谢
You don't need to double quote your variables. 您无需对变量加双引号。 So, for instance
因此,例如
curl_setopt ( $ch, CURLOPT_URL, "$url");
Should be 应该
curl_setopt ( $ch, CURLOPT_URL, $url);
Second, you need a curl_exec at the end to actually make the CURL request do something 其次,您需要在末尾使用curl_exec才能真正使CURL请求执行某些操作
curl_exec($ch);
Finally, at the very end, make sure you can debug the response in some fashion 最后,请确保您可以某种方式调试响应
if($err = curl_error($ch)) echo 'Error: ' . $err;
Here's how to add your header 这是添加标题的方法
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json', 'charset=utf-8'));
Your username/password setup is also wrong 您的用户名/密码设置也有误
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
To ensure that you make the request using Digest authentication, I'd include the following options in your php-curl request: 为确保您使用摘要式身份验证发出请求,我将在您的php-curl请求中包括以下选项:
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
Secondly, ensure you include the following headers in your request: 其次,确保在请求中包括以下标头:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept:application/json; charset=utf-8',
'Content-type:application/json; charset=utf-8'
));
Then in your Wowza installation, confirm that your Server.xml configuration under the RestInterface element has the following: 然后在Wowza安装中,确认RestInterface元素下的Server.xml配置具有以下内容:
<AuthenticationMethod>digest</AuthenticationMethod>
Lastly, if you run into more trouble, you can add the following debug elements to further investigate any remaining issues with your request (Under Server->RestInterface->Properties): 最后,如果遇到更多麻烦,可以添加以下调试元素,以进一步调查请求中的所有剩余问题(在“服务器”->“ RestInterface”->“属性”下):
<Property>
<Name>debugEnable</Name>
<Value>true</Value>
</Property>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.