in reply to HTTP/1.1 400 Bad Request

You might check your webserver's error logs, and see if there's any additional details in there.

For the CRLF issue, it's probably best not to use '\r\n', as '\n' is handled differently based on the OS you're using. I typically use "\015\012" for CRLF. (see perlport, 'Newlines' for details)

If that doesn't work, and you don't have access to the error logs to see what specific part of processing is throwing the error, I'd make sure that the request validates as XML, and against whatever schema you might have. (if that trailing semicolon is part of the message being sent, I'd suggest removing it).