# User authentication Problem via CURL Command

**URL:** https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178
**Category:** Wowza Developer Dojo
**Created:** [June 19, 2016, 12:59pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178 "2016-06-19T12:59:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sanjay\_yadav](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sanjay\_yadav](https://community.wowza.com/u/sanjay_yadav)
#### Post date: [June 19, 2016, 12:59pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/1 "2016-06-19T12:59:50Z")

</div>

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](https://www.wowza.com/forums/content...sh-publishing))

```auto
<?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:

```auto
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

```auto
USER Authentication problem

```

any help will apprenticed.

THANKS in advance.

---

<div class="post-metadata">

### Author: ![burak\_guder](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@burak\_guder](https://community.wowza.com/u/burak_guder)
#### Post date: [June 20, 2016, 3:31am UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/2 "2016-06-20T03:31:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![burak\_guder](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@burak\_guder](https://community.wowza.com/u/burak_guder)
#### Post date: [June 20, 2016, 11:24pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/3 "2016-06-20T23:24:55Z")

</div>

[PHP]\<?php

$appName = “enc”;

$url = “[http://localhost:8087/v2/servers/](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

---

<div class="post-metadata">

### Author: ![burak\_guder](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@burak\_guder](https://community.wowza.com/u/burak_guder)
#### Post date: [June 25, 2016, 2:25am UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/4 "2016-06-25T02:25:56Z")

</div>

update wowza 4.5

---

<div class="post-metadata">

### Author: ![Paul\_Shields](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/paul_shields/32/390_2.png) [@Paul\_Shields](https://community.wowza.com/u/Paul_Shields)
#### Post date: [July 6, 2016, 2:50pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/5 "2016-07-06T14:50:43Z")

</div>

> 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
> 
> ```auto
> <?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
> 
> ```auto
> 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,

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

```

Paul

---

<div class="post-metadata">

### Author: ![sanjay\_yadav](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sanjay\_yadav](https://community.wowza.com/u/sanjay_yadav)
#### Post date: [June 20, 2016, 2:15pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/6 "2016-06-20T14:15:37Z")

</div>

> 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

```auto
<?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

```auto
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

---

<div class="post-metadata">

### Author: ![sanjay\_yadav](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sanjay\_yadav](https://community.wowza.com/u/sanjay_yadav)
#### Post date: [June 21, 2016, 12:16pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/7 "2016-06-21T12:16:28Z")

</div>

> [PHP]\<?php
> 
> $appName = “enc”;
> 
> $url = “[http://localhost:8087/v2/servers/\_defaultServer\_/vhosts/\_defaultVHost\_/applications/“.$appName.”/actions/restart](http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/%22.$appName.%22/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

```auto
{"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

---

<div class="post-metadata">

### Author: ![mehmet\_keser](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mehmet\_keser](https://community.wowza.com/u/mehmet_keser)
#### Post date: [July 8, 2020, 1:14pm UTC](https://community.wowza.com/t/user-authentication-problem-via-curl-command/47178/8 "2020-07-08T13:14:17Z")

</div>

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
