In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to solve the problem of garbled Chinese characters obtained by the recipient of the HttpClient request". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to solve the problem of garbled Chinese characters obtained by the recipient of the HttpClient request".
Problem description
Spring Boot2.0 version project, which uses HttpClient to request data. The requested parameters contain Chinese characters. The request header is set as follows.
Headers.put ("Content-Type", "application/json; charset=utf-8")
There is no problem printing data output from my console.
Solution
After the request boss learned that the binding force of header setting is very limited, only constraining the request format, request body setting and so on, for coding problems, to use java.net.URLEncoder.encode (value) for transcoding processing, in the receiving side, use java.net.URLEncoder.decode (value) and then turn back.
Summary
Reference standard
According to the HTTP protocol, if there are special characters (such as: &, @, etc.) in the value of the passed parameter, it is necessary to URL Encoding the value so that the receiver of the request can receive the correct parameter value. In this case, the data to be signed should be the original value rather than the value after encoding. For example, when you need to digitally sign the request parameter email when calling an API, the data to be signed should be email=test@msn.com, not email=test%40msn.com.
At this point, I believe you have a deeper understanding of "how to solve the problem of garbled Chinese characters obtained by the recipient of the HttpClient request". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.