Wowza rest api to Create Application given Unauthorized

Hi i am trying to create application using rest api

Application objroot = new Application();

//Create Application Object//

objroot.restURI = “http://localhost:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications/” + name;

objroot.name = name;

objroot.appType = appType;

objroot.clientStreamReadAccess = “*”;

objroot.clientStreamWriteAccess = “*”;

objroot.description = description;

StreamConfig objstreamingconfig = new StreamConfig();

objstreamingconfig.restURI = “http://localhost:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications/”+name+"/streamconfiguration";

objstreamingconfig.streamType = appType;

//////////////////////////

objroot.streamConfig = objstreamingconfig;

//call Http client to post rest api…

HttpClient client = new HttpClient();

client.BaseAddress = new Uri(“http://localhost:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications/”+name+" -d");

//to set credentials on

var byteArray = Encoding.ASCII.GetBytes(UserName + “:” + Password);

client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(“Basic”, Convert.ToBase64String(byteArray));

////////////////

here i am getting response : Unauthorized

Please help me, what i am doing wrong ?

Hello

It’s uncertain as to what else is going on in the code there but I’d urge you to start with a curl request and then move that into your code base from there:

Simple example creating “testlive” application:

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",
   "clientStreamReadAccess": "*",
   "clientStreamWriteAccess": "*",
   "description": "Testing our Rest Service",
   "streamConfig": {
      "restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamconfiguration",
      "streamType": "live"
   }
}'

When you run your application I’d suggest printing out the generated json along with the headers used to ensure that it matches similarly to the above curl request. Should you have further problems please provide your post data along with your conf/ and logs/ (as a zip file) and send it to support@wowza.com.

Thanks,

Matt

Thanks for the update and glad you got this sorted.

Salvadore

Thanks for reply.

above code is working on my local side. the same code i am using on server ( dedicated server with remote desktop) its return response : Unauthorized

while when i uses rest api to get application list, this works on both computer ( my local and server) and return list of applications.

http://localhost:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications

i thought this is problem of users, but i am using admin that have full access, but still i am getting issue :(.

below is Error Details

StatusCode: 401, ReasonPhrase: ‘Unauthorized’, Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\u000d\u000a{\u000d\u000a Connection: keep-alive\u000d\u000a Transfer-Encoding: chunked\u000d\u000a Accept-Ranges: bytes\u000d\u000a Date: Wed, 16 Sep 2015 06:47:47 GMT\u000d\u000a Server: Restlet-Framework/2.2.2\u000d\u000a WWW-Authenticate: Digest realm=“Wowza”, domain="/", nonce=“MTQ0MjM4NjA2Nzg0NTpkYzg3OGQwZDEwNjU3YTFkMDljODdjZjgzZTgxYTdlZA==”, algorithm=MD5, qop=“auth”\u000d\u000a Content-Type: text/xml; charset=UTF-8\u000d\u000a}

while on the success on local i am getting response

ReasonPhrase: ‘Created’, Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\u000d\u000a{\u000d\u000a Connection: keep-alive\u000d\u000a Transfer-Encoding: chunked\u000d\u000a Accept-Ranges: bytes\u000d\u000a Date: Wed, 16 Sep 2015 07:02:43 GMT\u000d\u000a Server: Restlet-Framework/2.2.2\u000d\u000a Content-Type: application/json\u000d\u000a}"

Thanks

Hi,

Issue has been fixed. I found problem is on [wowza-install-dir]/conf/Server.xml file on Server. I changed the AuthenticationMethod to ‘basic’ and restart Wowza Streaming Engine service.

and now its works. :slight_smile: