0

I have a SOAP XML that at the start has a custom header that I wrote. I have TCP/IP Connection, and I receive Header + SOAP XML. The header has at the end \r\n\r\n. When I try to read the socket, I use bufferInputstream and it has readnextline, and that removes that \r\n\r\n that I use which means that I reached the end of the header, and hence I can not decode the header correctly. Is there a function that can ignore the carriage return and new lines, and stores the socket response in a string ?

4
  • BufferedOutputStream is for writing not reading, so it does not have a readNextLine method. Please post a relevant snippet of your code.
    – Aurand
    Apr 2, 2013 at 19:31
  • Thanks for the note. The problem that readNextLine, checks for \n. I use \r\n\r\n for knowing the end of my header. So while decoding the message and using readNextLine, it will removes my "tags".
    – Andre
    Apr 2, 2013 at 19:36
  • You'll have reached the end of the header when the line you get back is "\r".
    – Chris Nava
    Apr 2, 2013 at 19:47
  • @ChrisNava so I don't need to look for \r\n\r\n using .index of ? I just need to look for \r ?
    – Andre
    Apr 2, 2013 at 20:39

2 Answers 2

0

Just read until line.length() == 0. That's the one between the two \r\n sequences. The line terminators are removed by readLine(), and it handles both \r\n, \n, and for that matter \r by itself as line terminators.

1
  • @Mahmoud I did show sample code. You shouldn't need anything more.
    – user207421
    Apr 2, 2013 at 23:29
-1

You are using a LINE based parser so your string match can't extend to multiple lines. In your wile loop, look for a single line containing just "\r" (or just "" if it strips \r also) and that will be the one blank line between the Header and the Content.

2
  • My head looks like: Content-length 499 \r\n\r\n <?xml...etc
    – Andre
    Apr 2, 2013 at 22:55
  • It does strip the line terminators.
    – user207421
    Apr 3, 2013 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.