Here's a bit of working sample code. I'm using HttpClient.PostAsync called 
periodically. I'm not setting any headers. I'm using the PushStreamContent 
class for my content. I loop through the items in the queue and write them 
to the stream after converting them to UTF8.

private async Task SendQueue(ConcurrentQueue<char[]> queue, string 
retentionPolicyName)
{
var content = CreateContent(queue);
var uri = new Uri(_influxHttpdAddress).SetPath(_port, "write");
if (!_influxHttpdAddress.Contains("db="))
uri = uri.AddQuery("db", _databaseName);
if (!_influxHttpdAddress.Contains("rp="))
uri = uri.AddQuery("rp", retentionPolicyName);
try
{
var response = await _client.PostAsync(uri, content).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.BadRequest)
throw new Exception("Write failure: " + await 
response.Content.ReadAsStringAsync().ConfigureAwait(false));
// for debugging:
//if (response.StatusCode == HttpStatusCode.InternalServerError)
// throw new Exception("Server error: " + await 
response.Content.ReadAsStringAsync().ConfigureAwait(false));
//if (response.StatusCode != HttpStatusCode.NoContent)
// throw new Exception("Write failure: " + await 
response.Content.ReadAsStringAsync().ConfigureAwait(false));
}
catch (Exception ex)
{
logger.Error(ex);
// may fail during shutdown
}
}

-- 
Remember to include the InfluxDB version number with all issue reports
--- 
You received this message because you are subscribed to the Google Groups 
"InfluxDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/influxdb.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/influxdb/c9acc658-018d-4a77-a5ba-000a9119f991%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to