java curl 会删除换行符吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17456584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 02:03:57  来源:igfitidea点击:

Does curl remove new line characters?

javaspring-mvccurl

提问by user86834

I'm posting a text file that contains a list on multiple lines to my service via curl. When I read the body of the request in my Spring MVC controller there are no new line characters and all text is on one line.

我正在通过 curl 向我的服务发布一个包含多行列表的文本文件。当我在 Spring MVC 控制器中读取请求正文时,没有换行符,所有文本都在一行上。

Does curl remove new line characters? Is there a way to maintain the new line characters as I need them to parse the text. Here is a snippet code that I am using to read the post body:

curl 会删除换行符吗?有没有办法维护换行符,因为我需要它们来解析文本。这是我用来阅读帖子正文的片段代码:

    StringBuilder builder = new StringBuilder();
    String line = null;

    try {
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null) {// this is just one line of text!
            builder.append(line);
        }
    } catch (Exception e) { 
        //handle exception
    }

回答by lreeder

Yes, curl removes linebreaks from data posted with the -d option. Use --data-binary instead. See SO question How to send line break with curl?for more info.

是的,curl 会从使用 -d 选项发布的数据中删除换行符。改用 --data-binary 。请参阅 SO 问题如何使用 curl 发送换行符?了解更多信息。