0

The same C# code that works for inserting into local server works but not for actual server.

I think it has to do with credentials?

using (System.Net.WebClient client = new WebClient())
{
    //test
    client.Credentials = new NetworkCredential("username", "pw");
    client.UploadString(new Uri($"{Settings.influxDBServer}/write?db={Settings.influxDatabaseName}"), sb.ToString());
}

In local server username/pw isn't required. For enterprise it is. So I added the client.Credentials = new NetworkCredential("username", "pw"); line. I looked here and tried the answer by jitbit but I still get error 400.

peterdn
  • 2,386
  • 1
  • 23
  • 24
JJSSOQ
  • 49
  • 2
  • 10
  • What is the error message you are getting? – Will Dec 13 '17 at 16:28
  • @Will {"The remote server returned an error: (400) Bad Request."} – JJSSOQ Dec 13 '17 at 16:30
  • @JJSSOQ something about your request is badly formed. [InfluxDB docs say](https://docs.influxdata.com/influxdb/v1.4/query_language/authentication_and_authorization/#authentication-and-authorization-http-errors) that a 401 or 403 will be returned if there is a problem with credentials. Can you output the full Uri you are passing and also the contents of `sb.ToString()`? – peterdn Dec 13 '17 at 19:17
  • @Will It will insert into local server with no problem but not the enterprise one that requires credentials. sb.Tostring()--> {infoLog,ServerName=s001,ServerPort=39620,CacheType=abc-p.1,FarmType=Dev ConnectedClients=9,BlockedClients=0,UsedMemory=12900664,UsedMemoryPeak=31990728,InstantaneousOpsPerSec=8,RejectedConnections=0,KeyspaceHits=318,KeyspaceMisses=105,ConnectedSlaves=0 15131232000000000} ResponseUri = {http://example0005:8086/write?db=CachePreprocessor} – JJSSOQ Dec 13 '17 at 19:45

0 Answers0