简体   繁体   中英

What characters are html encoded?

TL;DR Düsseldor is encoded to Düsseldor, Düsseldorf isn't encoded (by the default MVC encoding) why?

I'm building an api with soap access. When I get a request I html encode all the data. Just before I end the current request I copy the Response.Stream and save it for logging.

I noticed that Düsseldorf is encoded by my api to "Düsseldorf". This is expected. But in my logs it shows Düsseldorf encoded as "Düsseldorf" ( double encoded ) my logs saves after the MVC serializes writes to the response stream.

I think this is because soap encodes values before sending them over the wire.

So my next test was to turn off html encoding in my api. So this time Düsseldorf was giving to the soap serializer.

But it was encoded as Düsseldorf?

EDIT: When I say I turn on / off the encoding what I mean is each field in the request I use HttpUtility.HtmlEncode("some field"). And save that to the database. Then I return the data with an MVC view like so:

public ActionResult CreateAccessCode ( CreateAccessCodeRequest request )
{
    var response = new Response (request);
    return new ContentResult (response);
}

My question is when the ContentResult method runs, it seems to do some encoding of its own and I was wondering what that was?

SOAP uses XML - HTML and XML require slightly different encoding, but it may or may not be a problem in your case.

Much more likely your manual construction of XML is not correct. Please do not construct XML with string concatenation - XDocument/XmlDocument are much more suitable for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM