Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does curl remove new line characters?

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.

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:

    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     } 
like image 910
user86834 Avatar asked Jul 03 '13 19:07

user86834


People also ask

Is New Line two characters?

You need to advance to the next line on the page AND return to the beginning of the line, hence CRLF , two characters.

How do I add a new line character?

Adding Newline Characters in a String In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.


1 Answers

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.

like image 195
lreeder Avatar answered Sep 27 '22 23:09

lreeder