This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22961|Reply: 1

[WebAPI] WebAPI receives Chinese garbled characters

[Copy link]
Posted on 8/19/2016 10:54:45 AM | | | |


I received the parameters in the webapi and then inserted them into the oracle database, and at first I thought it was an oracle database coding problem.

After thinking about it carefully, why do I use Google's browser plugin to post my interface, Chinese there is no garbled characters????

The post method you wrote yourself is garbled???????

Start debugging and find that the post method you wrote was garbled when the API received it.

So, it's not a problem with oracle coding.

Where did it come from???

The problem is:

The ContentType http header does not specify the encoding format, although we use utf-8 encoding to send the past, but the api does not know what encoding format you have.

Therefore, the API is decoded according to its own default encoding area, resulting in Chinese garbled characters.

Here's how to fix it:



byte[] bs = Encoding.UTF8.GetBytes(param);  Here to be changed,

Then add "; charset=UTF-8”。




Previous:Debug IIS pages by attaching processes in VS, and solve the problem of setting breakpoints that are invalid
Next:.net does WeChat development to obtain user information and scan function [with source code]
Posted on 2/24/2023 4:54:01 PM |
I just met it, thank you for sharing!!!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com