0

I had a discussion with someone and could not come to a proper solution so I wanted to know how you guys think about this:

I have a html form and the other guy call him 'Aron' has got a .net system. My html form has a input text field called description. Aron his .net system catches my description Post and then changes this data in to XML.

BUT if a special character like & is posted, then he will get a parse error.

Now Aron is telling me that i need to post the & data as & and not as raw &.

What do you guys think about this?

Nuri Ensing
  • 1,899
  • 1
  • 19
  • 42
  • 1
    This is normal, encoding prevents errors because characters like " and ' don't have to be escaped anymore. Also, why doesn't this happen in the .net part :p – Thaillie Dec 14 '15 at 10:30

2 Answers2

1

For me it sounds more like a server-side problem. If I were you, I would create an object, serialize it to JSON, send it to this .NET application and let .NET developer do whatever he needs with it. I have sent proper data in accordance with my arhitecture and language.

It would be more proper and reasonable. Imagine the case - you don't work with Aron anymore, you work with Mark who takes your POST data and saves as plain text. He will ask "why are you sending HTML-encoded data to me? I do not need this". You definitely won't tell him "just decode it back" and you definitely don't want to change your code every time you change a partner. What if you work with both of them at the same time, or with 10 services at the same time?

As a consumer of a service, you should not bother about how this service is implemented. Moreover, you may now know how it is implemented, and it shouldn't affect your code.

Yeldar Kurmangaliyev
  • 33,467
  • 12
  • 59
  • 101
0

I think the honourable gentleman Aron should use an appropriate library that deals with issues such as this and more, used correctly it should be almost automatic.

Failing this, he can use System.Web.HttpUtility.HtmlEncode() before converting to XML.

It can be done client side, using javascript to fiddle with the data before it gets sent... but this in my opinion is bad practice and should be handled by the server.

An alternative is encoding the html entities using htmlspecialchars() in PHP yourself, then using CURL to post the data to his ".net system".

Sworrub Wehttam
  • 588
  • 4
  • 14
  • Turns out the "appropriate library" is System.XML, see http://stackoverflow.com/questions/157646/best-way-to-encode-text-data-for-xml – Sworrub Wehttam Dec 14 '15 at 10:45