0

I integrated my website with a 3rd party API, and for some reason when I send my XML request file all the spaces I have in the request comes back with no spaces. For example, if I have "123 Main Street" it would get returned as "123MainStreet".

The 3rd party API support team says it's the way I'm encoding the XML request when submitting it; which is causing the spaces to be removed, but I use the same method with other APIs and I don't have this issue.

They then tell me that I could use a "plus sign (+)" in my XML request to resolve this issue, like the following example; which ends up working but then I can't view my XML request anymore in my browser.

<STREET1>123+Main+Street</STREET1>

I then get the "XML Parsing Error: Not Well-Formed" message. However, I can still see the XML request but I have to now "view page source" in my browser to see it, while before when I didn't add the "plus sign (+)" it would show up fine in my browser.

Does anyone know how I can get my XML request to show properly again with the "plus sign (+)" still in the request file?

Or is there another "encoding method" I should be trying this way the spaces don't get removed when I submit my XML request file to the API?

Thank you!

olimits7
  • 555
  • 2
  • 9
  • 26
  • Since none of what you describe sounds like something one would normally experience when sending XML to and from an API, I think you're going to give us some more information. Can you tell us what this 3rd party API is? How you're sending your requests to it (HTTP request, etc.)? – JLRishe Nov 17 '16 at 05:23

1 Answers1

0

My guess would be that you are transmitting the XML as a parameter on a URI sent to the web server, perhaps even on an ordinary HTTP GET request. That's very bad API design (GET requests should never be used for requests that change state on the server) but it they've designed it that way then you'll probably have to live with it.

Encoding space as plus sign will work in the query part of a URI (see for example When to encode space to plus (+) or %20?). But XML contains many other special characters that need to be encoded too, so you really need a more general solution, namely percent-encoding (where space becomes %20, '<' becomes %3C), etc. Depending what language you're writing in, you'll find some library routine that does this for you.

Community
  • 1
  • 1
Michael Kay
  • 156,231
  • 11
  • 92
  • 164