Skip to content

Instantly share code, notes, and snippets.

@olegchir
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchir/02f2504a1d817d7e001a to your computer and use it in GitHub Desktop.
Save olegchir/02f2504a1d817d7e001a to your computer and use it in GitHub Desktop.
using System;
using System.Net;
using System.IO;
namespace FlussonicApiTest
{
class MainClass
{
public static void Main (string[] args)
{
const string ServerAddress = "http://portal:8080";
const string UserName = "flussonic";
const string Password = "letmein!";
const string ApiMethod = "/flussonic/api/config/stream_create";
const string HTTPRequestPayload = "stream mystream3 hls://myvideo.com/myvideo;";
string result = FlussonicApiCall(ServerAddress,UserName,Password,ApiMethod,HTTPRequestPayload);
Console.WriteLine (result);
Console.WriteLine ("Press any key to stop");
Console.ReadKey ();
}
public static string FlussonicApiCall(
string ServerAddress,
string UserName,
string Password,
string ApiMethod,
string HTTPRequestPayload
) {
string RemoteUrl = ServerAddress + ApiMethod;
var httpReq = (HttpWebRequest)WebRequest.Create (RemoteUrl);
httpReq.Credentials = new NetworkCredential (UserName, Password);
httpReq.Method = "POST";
httpReq.Accept = "application/json";
httpReq.ContentType = "text/plain";
using (var stream = httpReq.GetRequestStream ())
using (var sw = new StreamWriter(stream))
{
sw.Write (HTTPRequestPayload);
}
string result = "";
using (var response = httpReq.GetResponse ())
using (var stream = response.GetResponseStream ())
using (var reader = new StreamReader (stream))
{
result = reader.ReadToEnd ();
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment