All kinds of error __java running curl in Java

Source: Internet
Author: User
Tags curl

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.