C # HttpRequest and various encodings

Here is my problem. I have a site in ASP.NET/C# that receives some data through GET / POST

This is "user-filled" data, but not through a web page, this is the software that communicates with my server.

The problem is that this software is sending data encoded in ISO-8859-1 (so the cafe will be sent to Caf% E9) and the rest of my Unicode SW / DB

Also, the data becomes completely crippled, which makes it impossible to restore what was sent: /

What would be the best way to handle this?

I tried setting Request.ContentEncoding (before reading), but it didn't help.

+3
source share
5 answers

, , web.config:

<configuration>
  <system.web>
    <globalization requestEncoding="iso-8859-1"/>
  </system.web>
</configuration>

Request["varName"]

HttpUtility.UrlDecode HttpUtility.UrlEncode, 2 . [] .

JamesP .

+3

% e9 - é, UrlEncoded. Server.UrlDecode .

+1

- ASP.NET

Short:

web.config

<configuration>
  <system.web>
    <globalization
      fileEncoding="utf-8"
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      culture="en-US"
      uiCulture="de-DE"
    />
  </system.web>
</configuration>

aspx.

utf-8 , utf-16

, .

+1

.

, Web.config,

requestEncoding = "ISO-8859-1"

, !

+1

, HTTP-. , HTTP, .

You can use System.Text.Encoding.GetEncoding (...) to retrieve the Encoding object for ISO-8859-1. Then call GetDecoder () for this encoding object and use it to interpret the request body. Ideally, you determine the type of encoding that you load from Encoding.GetEncoding (...) from the header values ​​in the request, so servers with different configurations are supported.

0
source

Source: https://habr.com/ru/post/1699105/


All Articles