Last active
August 29, 2015 14:06
-
-
Save olegchir/02f2504a1d817d7e001a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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