卷曲会删除新行字符吗?

2022-09-01 00:06:38

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

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

    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
    }

答案 1

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


答案 2

推荐