User authentication Problem via CURL Command

Hi Guys,

I know this is not the Programming forums but this forums is related to the wowza and my question is totally related to the WOWZA.

I have check this JSON String

https://www.wowza.com/forums/content…sh-publishing)

<?php
$username = 'test';
$password = 'test';
$data = array(
"restURI" => "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/myStream/pushpublish/mapentries/ppsource",
"serverName" => "_defaultServer_",
        "sourceStreamName" => "myStream",
        "entryName" => "RTMP",
        "profile" => "rtmp",
        "host" => "rtmp",
        "application" => "myStream",
        "streamName"=>   "test",
        "userName" => "",
        "password"=> "",
        "debugPackets"=>"true",
        "sendReleaseStream"=>"false",
        "sendStreamCloseCommands"=>"false",
        "debugLog"=>"true",
        "destinationName"=>"rtmp",
        ); 
    $data_string = json_encode($data);
$url = 'http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/myStream/pushpublish/mapentries/ppsource';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec( $ch );
echo $result;
echo "data";

ERROR:

HTTP/1.1 401 Unauthorized
        Content-Type: text/xml; charset=UTF-8
        Date: Fri, 17 Jun 2016 18:43:07 GMT
        Accept-Ranges: bytes
        Server: Restlet-Framework/2.2.2
        WWW-Authenticate: Digest realm="Wowza", domain="/", nonce="dfsdfdfsdfsdfsdfsdfsdfTRlYjE1ZTgzZGYxODFmODQyZjYwYg=="algorithm=MD5, qop="auth"
        Connection: keep-alive
        Transfer-Encoding: chunked
       <?xml version="1.0" encoding="UTF-8" standalone="no"?><error><wowzaServer>4.2.0 < /wowzaServer><code>401</code><message>The request requires user authentication</message></error>data</body>
*<message>The request requires user authentication</message>*

I am getting

USER Authentication problem

any help will apprenticed.

THANKS in advance.

Hi

use php curl function

[PHP]private function sendCurlData($json, $apiURL) {

$ch = curl_init ( $apiURL );

curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, “POST” );

curl_setopt ( $ch, CURLOPT_POSTFIELDS, $json );

curl_setopt ( $ch, CURLOPT_USERPWD, $this->_User . “:” . $this->_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 );

return $contents;

}[/PHP]

essential feature

curl_setopt ( $ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST );

[PHP]<?php

$appName = “enc”;

$url = “http://localhost:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications/”.$appName."/actions/restart";

echo sendCurlData($url);

function sendCurlData($apiURL) {

$ch = curl_init ( $apiURL );

// curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, “POST” );

//curl_setopt ( $ch, CURLOPT_POSTFIELDS, $json );

curl_setopt ( $ch, CURLOPT_USERPWD, “burakguder:123456”);

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 );

return $contents;

}

?>[/PHP]

try again

update wowza 4.5

Hi burakguder,

Thank you so much for your Replay, I could totally Created the Stream with this code but when I need to restart the APPLICATION i wrote this code

<?php
//$appName = "enc";
$url = "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{appName}/actions/restart";
$ch = curl_init($url);
                
                //curl_setopt ( $ch, CURLOPT_URL, $url);
                curl_setopt ( $ch, CURLOPT_POST, 1 );
				curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_USERPWD, "admin:admin");                                                            
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
				curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json', 'charset=utf-8'));
				$res = curl_exec($ch);
				echo $res;
				if($err = curl_error($ch)) echo 'Error: ' . $err;
                curl_close ($ch);				
?>

ERROR

4.2.0405The method specified in the request is not allowed for the resource identified by the request URI

please let me know how can i solve this out.

thanks

Hi,

Change your setopt from CURLOPT_POST to CURLOPT_PUT. As an example using curl,

curl -X PUT --header 'Accept: application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/actions/restart

Paul

Hi

use php curl function

[PHP]private function sendCurlData($json, $apiURL) {

$ch = curl_init ( $apiURL );

curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, “POST” );

curl_setopt ( $ch, CURLOPT_POSTFIELDS, $json );

curl_setopt ( $ch, CURLOPT_USERPWD, $this->_User . “:” . $this->_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 );

return $contents;

}[/PHP]

essential feature

curl_setopt ( $ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST );

Hi burakguder,

Thank you so much for your Replay, I could totally Created the Stream with this code but when I need to restart the APPLICATION i wrote this code

<?php
//$appName = "enc";
$url = "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{appName}/actions/restart";
$ch = curl_init($url);
                
                //curl_setopt ( $ch, CURLOPT_URL, $url);
                curl_setopt ( $ch, CURLOPT_POST, 1 );
				curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_USERPWD, "admin:admin");                                                            
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
				curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json', 'charset=utf-8'));
				$res = curl_exec($ch);
				echo $res;
				if($err = curl_error($ch)) echo 'Error: ' . $err;
                curl_close ($ch);				
?>

ERROR

4.2.0405The method specified in the request is not allowed for the resource identified by the request URI

please let me know how can i solve this out.

thanks

[PHP]<?php

$appName = “enc”;

$url = “http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/“.$appName.”/actions/restart”;

echo sendCurlData($url);

function sendCurlData($apiURL) {

$ch = curl_init ( $apiURL );

// curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, “POST” );

//curl_setopt ( $ch, CURLOPT_POSTFIELDS, $json );

curl_setopt ( $ch, CURLOPT_USERPWD, “burakguder:123456”);

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 );

return $contents;

}

?>[/PHP]

try again

{"success":false,"message":"Unknown action: restart","data":null}

this is the output and i still can’t restart the Application.

please Help , thanks for your time

merhaba burak bey bu yazdıgınız kodları php olarak nasıl calıstırabılırım yardımcı olursanız sevınırım