Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi all,

I am working on project where 2 web application need to communicate with each other (1 way communication).
The first web app POST xml data to our web app.
Whenever there is special caracters in the xml data, the reciver get corrupted data.
Is there a way to avoid this in the reciver app ?

I know i can use some HtmlEncrypt/HtmlDecrypt but if possible i dont want to force the client to do any work.

What I have tried:

Here is the xml sending code :

C#
<pre>HttpResponse response = HttpContext.Current.Response;
            response.Clear();

            StringBuilder s = new StringBuilder();
            s.Append("<html>");
            s.Append("<body onload='document.forms[\"form\"].submit()'>");
            s.AppendFormat("<form name='form' action='{0}' method='post'>", url);
            s.AppendFormat("<input type='hidden' name='xmlData' value='{0}' />", xmlData);
            s.Append("</form></body></html>");
            response.Write(s.ToString());
            response.End();


This is just for tests purpuses, i have no idea hwo the client will do this, nor the technologies he uses.

And this is the Get POST xml

C#
<pre>private string GetPostXmlData()
        {
            string[] keys = Request.Form.AllKeys;
            string value = String.Empty;
            if (keys.Length > 0)
                value = Request.Form[keys[0]];

            return value;
        }



thanks.
Posted
Updated 10-Apr-18 0:55am

1 solution

s.AppendFormat("<input type='hidden' name='xmlData' value='{0}' />", System.Net.WebUtility.HtmlEncode(xmlData));
 
Share this answer
 
Comments
Ziee-M 10-Apr-18 7:43am    
I accept this answer even thought i said in my description that this is not a valid solution.
I wanted to manage this in my reciver code not in the sender(the sender will be developped by some other dev).
F-ES Sitecore 10-Apr-18 7:47am    
You need to assume the sender is using the correct method for sending xml data, so if you're not involved in the sending I'm not sure why you're concerned what method they use to do the sending as long as it works. If the sender is sending you corrupted values it is their responsibility to fix their process, not yours.
Ziee-M 10-Apr-18 7:49am    
Indeed you are right, but if i can handle it my code, that would be even better.
F-ES Sitecore 10-Apr-18 7:53am    
We don't know what the corrupted data looks like so it's impossible to say how to handle it.
Ziee-M 10-Apr-18 7:57am    
Anything after the special character is removed. But, no need for further help, you are totaly right,its thier job to encode the data before sending it!
Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900