File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to send HTTP Post with XML that contains non ascii charachters

 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have code that works fine in some circumstances :


Where data is an xml string.

This code works fine unless my xml string has any non ascii characters in it. For examaple, if the xml is this

The & character seems to break this.
On the receiving end of the post, I get the xml all the way up to but not including the & character.


I tried to do the following : request.content_type = 'text/xml', but that actually made things worse!
Any tips?
Thanks,
Kim
 
Paul Clapham
Sheriff
Pie
Posts: 20164
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ampersand is a perfectly ordinary ASCII character. However it's possible that you haven't escaped it properly in your XML document, which might cause problems.
 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply Paul,
I have tried to escape the character like this :

& amp; (no space between & and amp; but couldn't get it to show up here any other way)

but it did not help. Would you recommend a different way to treat the & ?
Thanks,
Kim
 
Paul Clapham
Sheriff
Pie
Posts: 20164
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be well-formed XML your document should look like this:

However it isn't clear whether this is an HTTP problem or an XML problem. Have you tested it with plain text data containing ampersands? (Or is the use of XML an integral part of that Ruby code?)
 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, yes that is exactly what my xml looks like. I do need to pass the string as xml.
 
Paul Clapham
Sheriff
Pie
Posts: 20164
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it was a GET method, I would say the ampersand could be treated as the ampersand which separates two URL parameters. And hence you would lose the ampersand and everything after it, just as you describe. The cure for this would be to URL-encode the XML document, or something like that.

But it's a POST method. And it's Ruby, which ought to be taking care of that sort of thing anyway.

I would still try passing something which isn't XML but which does contain an ampersand, just to see whether you are dealing with an XML parsing issue or an HTTP parameter issue like the one I just outlined.
 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, just thought of something I didn't mention which may make a difference. The ruby app is sending the payload to a Java Spring application.
I am debuging the Java application and that is where I see the malformed XML arriving. I am taking the xml off the request in a controller method on the Java side.


Thank you so much for sticking with me on this !!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic