Home  >  Article  >  Web Front-end  >  How to solve the problem of garbled characters after uniapp submission

How to solve the problem of garbled characters after uniapp submission

藏色散人
藏色散人Original
2020-12-09 17:59:477171browse

Solution to garbled characters after uniapp is submitted: 1. Encapsulate the value to be transmitted into an object at the front end and pass it to the back end; 2. In the back end, modify the receiving format to "@RequestBody", that is Just receive the json format.

How to solve the problem of garbled characters after uniapp submission

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer.

Recommended (free): uni-app development tutorial

##uni-app front-end get request is passed to the back-end Chinese value garbled problem

Record some garbled code problems encountered when doing final design

1. At the beginning, I used the get method to transfer values ​​to the back-end springboot. It was very friendly when debugging the h5 page. There was no error and everything went smoothly.

How to solve the problem of garbled characters after uniapp submission
How to solve the problem of garbled characters after uniapp submission

2. However, when I open the mobile phone simulator for real-device debugging. . . An accident came:

How to solve the problem of garbled characters after uniapp submission The error message displayed by the name in the background is probably like this. I forgot to cut the picture (my name was entered in Chinese: fruit):

/search/itemname?name="

9x8x9c8b5cv"&page=1&num=12, invalid characters found in the request header

Because the get request occurs in the url request header, so I searched everywhere for solutions to garbled characters, but all I found were decoding in the background.

How to solve the problem of garbled characters after uniapp submission

This did not meet my requirements, because the request header was garbled, and it was simply Didn't enter the program, so it's useless.

After all the trouble, I finally felt that it would be better to use

post to request. So:

3. The front end encapsulates the value to be transmitted into an object and passes it to the back end:

How to solve the problem of garbled characters after uniapp submission It prints out like this:

How to solve the problem of garbled characters after uniapp submission

Send a request in json format to the backend

How to solve the problem of garbled characters after uniapp submission

4. For the backend, change the receiving format to @ RequestBody–that is, the json receiving format (Es7msg is an object I defined and used to receive values)

How to solve the problem of garbled characters after uniapp submission

Then you can successfully get the desired value

How to solve the problem of garbled characters after uniapp submission

I would like to remind everyone that it is best to use post to pass values, which can avoid a lot of garbled characters.

The above is the detailed content of How to solve the problem of garbled characters after uniapp submission. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn