I have a Java based application which sends data to a .NET based application through HTTP post. The data is XML string which is HTML encoded by Java application using the below code before the post.
Source xmlInput = new StreamSource(new StringReader(xStream.toXML(appData))); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer trans = transformerFactory.newTransformer(); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-16"); StreamResult result = new StreamResult(new StringWriter()); trans.transform(xmlInput, result); txtLoanAppXml = result.getWriter().toString();
On the .Net application side the data is decoded and deserialized using the below code
var xmlData = HttpUtility.HtmlDecode(Request.Form["txtLoanAppXml"]);var serializer = new XmlSerializer(typeof(MyCustomObject)); ApplicationData applicationData = serializer.Deserialize(new System.IO.StringReader(xmlData.ToString())) as MyCustomObject;
This works perfectly but deserialization fails when there are special characters in the post - for example '&'. Sample XML that fails is like below:
<?xml version="1.0" encoding="utf-16"?><MyData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <MyNode1>Test1 & Test2</MyNode1> <MyNode2></MyNode2> <MyNideN></MyNodeN></MyData>
I have tried to post the same XML string data using a .net test application where I have encoded using
HttpUtility.HtmlEncode(XmlData)and here I do not face any issue with deserialization when '&' is present in data.
What I have noticed is when data is encoded in .Net there is an additional
amp; added which is missing when encoded in java.
MyNode1>Test1 &amp; Test2</MyNode1>MyNode1>Test1 & Test2</MyNode1>
Any inputs on how to make this work will be very helpful.
I am trying to download a file using System.Web.HttpContext.Current.Response using the following code:
HttpResponse objResponse = System.Web.HttpContext.Current.Response;
I am encoding the file name using:
FileName = Uri.EscapeDataString(FileName);
The file is downloading correctly, except when I have comma or dot in the file name.
In that case, while downloading the file, the explorer cannot decode the comma back.
Original file name: Testing, FileEncoded name: Testing%2C%20fileDownloaded file name: Testing%2C file
Is there any way to code/encode the file name, in order to keep the commas and dots?
Given the text
<b>This is some text</b>
I want to write it to my page so that it shows up like this:
<b>This is some text</b>
and not like this
This is some text
escape("<b>This is some text</b>") gives me this lovely gem in firefox
not exaclty what I'm after. Any ideas?
I have a webform that allows users to upload text as Markdown.
The Markdown is converted to Html on the server(using Markdig) and also stored.
When displaying the converted Html that the user uploaded, should I @Html.Encode the content - the project is in c#, MVC 5/razor with request validation on.
i have a simple twitter share button that shares a text that contains a special character: the character is "è" which translates to
this collides with how the text must be formatted to share it, works fine for everybody except for IE11 and IE10, which simply cuts the text from the special character to the end of the string.
this is the code (simplified):
so this should share "www.website.com Bla bla è bla bla" but on IE it renders: "Bla bla" and it gets trunkated like this.
the charset of the page is set to
utf-8 and the html encoding of the special character works everywhere but in IE11-10, even if i launch the share panel via the simple
I'm not using the twitter api for sharing.
any help is greatly appreciated. thanks