I have a curl call that will connect to a data stream and return a value every time a new one is posted to the data stream.
curl -XPOST -d uuid=\"94701e51-a24f-42b8-b8fd-81e0ecb79a2b\" http://bms.org/republish
I've tried making a HttpClient post that generates the same http request using this code
Main:
static async Task Main(string[] args)
{
Republish r = new Republish(); //The class name.
try
{
Task.Run(() => r.Test()).Wait();
Console.WriteLine("bla");
Console.ReadKey();
}
catch (Exception ex) //Exceptions here or in the function will be caught here
{
Console.WriteLine("Exception: " + ex.Message);
}
}
public async Task<string> Test()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("curl", "7.48.0"));
client.DefaultRequestHeaders.ExpectContinue = false;
var requestContent = new StringContent("uuid=\"94701e51-a24f-42b8-b8fd-81e0ecb79a2b\"", Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage response = await client.PostAsync("http://bms.org/republish", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
Console.WriteLine(await reader.ReadToEndAsync());
}
//I never got to the return statement because it breaks.
}
But this never yields anything. After some searching around I think it's because await client.PostAsync is waiting for the entire payload to be received before it streams it.
How can I stream it in real time?