Note that there are some explanatory texts on larger screens.

plurals
  1. POC#, UTF-8 and encoding characters
    text
    copied!<p>This is a shot-in-the-dark, and I apologize in advance if this question sounds like the ramblings of a madman.</p> <p>As part of an integration with a third party, I need to UTF8-encode some string info using C# so I can send it to the target server via multipart form. The problem is that they are rejecting some of my submissions, probably because I'm not encoding their contents correctly.</p> <p>Right now, I'm trying to figure out how a dash or hyphen -- I can't tell which it is just by looking at it -- is received or interpreted by the target server as <code>?~@~S</code> (yes, that's a 5-character string and is not your browser glitching out). And unfortunately I don't have a thorough enough understanding of <code>Encoding.UTF8.GetBytes()</code> to know how to use the byte array to begin identifying where the problem might lie.</p> <p>If anybody can provide any tips or advice, I would greatly appreciate it. So far my only friend has been MSDN, and not much of one at that.</p> <p><strong>UPDATE 1</strong>: After some more digging around, I discovered that using <code>System.Web.HttpUtility.UrlEncode()</code>to encode an EM DASH character ("—") will hex-encode it into "%e2%80%94".</p> <p>I'm currently sending this info in a<code>HttpWebRequest</code>post, with a content type of "application/x-www-form-urlencoded" -- could this be what's causing the problem? And if so, what is the proper way to encode a series of name-value pairs whose values may contain Unicode characters, such that it will be understood by a server expecting a UTF-8 request?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload