• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!
 
reply
    Bookmark Topic Watch Topic
  • New Topic