user3678053 user3678053 - 11 months ago 88
HTTP Question

use Java client like curl with param

I use influxdb 0.9. in this version, i can write database like

curl -XPOST 'http://localhost:8086/write?db=mydb' -d 'cpu,host=server01,region=uswest value=1.0'

Now I convert it to java

URL url = new URL("http", "localhost", 8086, "/write?db=mydb");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
OutputStream wr = con.getOutputStream();
Stirng s = "cpu,host=server01,region=uswest value=51.0";

but it doesn't work. Is the "-d" meant to represent post parameters? How can I express that in Java?

Answer Source

In this example the curl flag should really be --data-binary, not -d, which can have different encoding. As long as your string is unaltered by the Java code it should be fine. Anything like URL encoding will prevent the line protocol insert from working.