aspose file tools*
The moose likes Ruby and the fly likes Trying to send HTTP Post with XML that contains non ascii charachters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Trying to send HTTP Post with XML that contains non ascii charachters" Watch "Trying to send HTTP Post with XML that contains non ascii charachters" New topic
Author

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

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 17, 2001
Posts: 274
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 17, 2001
Posts: 274
Thanks, yes that is exactly what my xml looks like. I do need to pass the string as xml.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 17, 2001
Posts: 274
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 !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to send HTTP Post with XML that contains non ascii charachters