Recently, in the study of Elasticsearch, Java Run Curl to create a snapshot warehouse, Linux and Windows directly run the Curl command is not a problem, run in Java on a variety of error, curl code as follows
public static void Curl (string type, string url) {
string[] Cmds = {"Curl", type, url};
Processbuilder PB = new Processbuilder (CMDS);
Pb.redirecterrorstream (true);
Process p;
try {
p = pb.start ();
BufferedReader br = null;
String line = null;
br = new BufferedReader (New InputStreamReader (P.getinputstream ()));
while (line = Br.readline ())!= null) {
System.out.println ("T" + line);
}
Br.close ();
} catch (IOException e) {
e.printstacktrace ();
}
}
The requests submitted are as follows:
Curl-xput http://192.168.3.100:9200/_snapshot/back_2/back_6-d "{\" indices\ ": \" indexdemo1\ "}"
Various escape attempts have been made that cannot be committed in Java, unmatched brace in column error, could not resolve host error, unmatched close brace/bracket in Column error over two days, no patience, and finally inadvertently see a strange solution, the request address in quotation marks, and then the-D argument with 3 quotes, in desperation, any way to try
String url = "\" http://192.168.3.100:9200/_snapshot/back_2/back_133\ "D \" {\ "\" \ "indices\" \ "\": \ "\" \ "indexdemo1\" \ "\"}\"";
Finally successfully submitted ...
I hope I can help my friend in the back pit.