首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wowza rest api to php脚本

wowza rest api to php脚本
EN

Stack Overflow用户
提问于 2015-11-12 14:13:48
回答 1查看 1.5K关注 0票数 0

我是php和wowza的新手,不知道有没有人能告诉我如何在php中使用这个wowza curl api?我试过寻找,但在任何地方都找不到答案,所以我来到这里。我想要实现的是通过php从远程计算机运行这个curl

这是我想要转换成php脚本的curl之一,但是我似乎找不到我应该从哪里开始或者如何开始。

代码语言:javascript
复制
curl -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive -d'
{
   "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive",
   "name": "testlive",
   "appType": "Live",
   "description": "Testing our Rest Service",
   "streamConfig": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamconfiguration",
      "streamType": "live"
   },
   "securityConfig": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/security",
      "secureTokenVersion": 0,
      "clientStreamWriteAccess": "*",
      "publishRequirePassword": true,
      "publishPasswordFile": "",
      "publishRTMPSecureURL": "",
      "publishIPBlackList": "",
      "publishIPWhiteList": "",
      "publishBlockDuplicateStreamNames": false,
      "publishValidEncoders": "",
      "publishAuthenticationMethod": "digest",
      "playMaximumConnections": 0,
      "playRequireSecureConnection": false,
      "secureTokenSharedSecret": "",
      "secureTokenUseTEAForRTMP": false,
      "secureTokenIncludeClientIPInHash": false,
      "secureTokenHashAlgorithm": "",
      "secureTokenQueryParametersPrefix": "",
      "secureTokenOriginSharedSecret": "",
      "playIPBlackList": "",
      "playIPWhiteList": "",
      "playAuthenticationMethod": "none"
   },
   "modules": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/modules",
      "moduleList": [
         {
            "order": 0,
            "name": "base",
            "description": "Base",
            "class": "com.wowza.wms.module.ModuleCore"
         },
         {
            "order": 1,
            "name": "logging",
            "description": "Client Logging",
            "class": "com.wowza.wms.module.ModuleClientLogging"
         },
         {
            "order": 2,
            "name": "flvplayback",
            "description": "FLVPlayback",
            "class": "com.wowza.wms.module.ModuleFLVPlayback"
         },
         {
            "order": 3,
            "name": "ModuleCoreSecurity",
            "description": "Core Security Module for Applications",
            "class": "com.wowza.wms.security.ModuleCoreSecurity"
         }
      ]
   }
}'
EN

回答 1

Stack Overflow用户

发布于 2015-12-04 04:45:47

如上所述,看看php cURL扩展。然后查看以下示例脚本:

代码语言:javascript
复制
// If you have digest auth turned on, switch this to true.
$useDigest = false;
$username = "admin";
$password = "pass";

$json = '{
   "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow",
   "name": "stackoverflow",
   "appType": "Live",
   "description": "Testing our Rest Service",
   "streamConfig": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow/streamconfiguration",
      "streamType": "live"
   },
   "securityConfig": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow/security",
      "secureTokenVersion": 0,
      "clientStreamWriteAccess": "*",
      "publishRequirePassword": true,
      "publishPasswordFile": "",
      "publishRTMPSecureURL": "",
      "publishIPBlackList": "",
      "publishIPWhiteList": "",
      "publishBlockDuplicateStreamNames": false,
      "publishValidEncoders": "",
      "publishAuthenticationMethod": "digest",
      "playMaximumConnections": 0,
      "playRequireSecureConnection": false,
      "secureTokenSharedSecret": "",
      "secureTokenUseTEAForRTMP": false,
      "secureTokenIncludeClientIPInHash": false,
      "secureTokenHashAlgorithm": "",
      "secureTokenQueryParametersPrefix": "",
      "secureTokenOriginSharedSecret": "",
      "playIPBlackList": "",
      "playIPWhiteList": "",
      "playAuthenticationMethod": "none"
   },
   "modules": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow/modules",
      "moduleList": [
         {
            "order": 0,
            "name": "base",
            "description": "Base",
            "class": "com.wowza.wms.module.ModuleCore"
         },
         {
            "order": 1,
            "name": "logging",
            "description": "Client Logging",
            "class": "com.wowza.wms.module.ModuleClientLogging"
         },
         {
            "order": 2,
            "name": "flvplayback",
            "description": "FLVPlayback",
            "class": "com.wowza.wms.module.ModuleFLVPlayback"
         },
         {
            "order": 3,
            "name": "ModuleCoreSecurity",
            "description": "Core Security Module for Applications",
            "class": "com.wowza.wms.security.ModuleCoreSecurity"
         }
      ]
   }
}';

$ch = curl_init("http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/stackoverflow");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

if($useDigest){
    curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept:application/json; charset=utf-8',
    'Content-type:application/json; charset=utf-8',
    'Content-Length: '.strlen($json)
));
$contents = curl_exec($ch);
curl_close($ch); 
$response = json_decode($contents);

var_dump($response);

这将产生类似于以下内容的输出:

代码语言:javascript
复制
object(stdClass)#1 (3) {
  ["success"]=>
  bool(true)
  ["message"]=>
  string(49) "Application (stackoverflow) created successfully."
  ["data"]=>
  NULL
}

您可以找到其他几个cURL examples,您可以简单地操作与动词类型(在本例中为POST)一起发送的JSON,以进一步利用REST API。

检索现有应用程序的GET请求示例,您可以删除CURLOPT_POSTFIELDS cURL选项并修改以下行:

代码语言:javascript
复制
$ch = curl_init("http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33665405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档