1

I'm trying to write a simple query command. Documentaion for http for influxDB is here.

This is what I have so far:

WebClient client = new WebClient();
client.Credentials = new NetworkCredential("root", "root");
var reponse = client.UploadString("http://localhost:8080/query", "db=dbName\"q = SELECT \"something\" FROM \"tableName\" WHERE \"tag\"='valueTag'");

I'm getting "The remote server returned an error: (400) Bad Request.". Is it because the urlencode is not the same as putting as the string for the data part of client.UploadString?

agrm
  • 3,735
  • 4
  • 26
  • 36
JJSSOQ
  • 49
  • 2
  • 10

1 Answers1

1

WebClient.UploadString sends data as part of a POST request, which isn't what you want for this operation. Instead, your query should be URL-encoded and sent as HTTP GET parameters in the request URL. This can be achieved using Uri.EscapeUriString and WebClient.DownloadString:

var client = new WebClient();
var queryString = Uri.EscapeUriString("db=dbName&q=SELECT \"something\" FROM \"tableName\" WHERE \"tag\"='valueTag'");
var queryUrl = "http://localhost:8086/query?" + queryString;
var response = client.DownloadString(queryUrl);

Also note that HTTP GET parameters are separated by an ampersand and there must not be whitespace between the key/value names and the = or &. For example ?k1=v1&k2=v2 is well-formed whereas ?k1=v1&k1 = v1 is not.

peterdn
  • 2,386
  • 1
  • 23
  • 24
  • that code does not seem to work for me. I get an error of bad request 400. I made a new question https://stackoverflow.com/questions/47797900/400-bad-request-error-when-trying-to-insert-into-influxdb-enterprise-server-but . I think it has something to do with credentials – JJSSOQ Dec 13 '17 at 18:56