Article Directory
Background Description
The front end through a form submitted data with the Chinese, the back end wants to process the data. request.body
Is a binary
variable, although it can be decoded into utf8
but still not Chinese form, similar to
%E8%BF%98%E6%AC%BE%E6%88%90%E5%8A%9F%E9%A1%B5
After checked the relevant answer, I find a viable way to look at this record.
Solution
The front end of the HTML file specified form
parameters form, as follows:
<form action="/" method="post" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded">
</form>
Back-end post
process is as follows:
import tornado
import urllib.parse
class MyTestHandler(tornado.web.RequestHandler):
def get(self):
self.render('test.html')
def post(self):
body = self.request.body.decode('utf8')
body = urllib.parse.unquote(body)
print(body)
# something else
# self.render('test.html')
My front-end results of the two Chinese text input
results are as follows:
文案内容_0=这是一个测试文案&文案内容_1=这是另一个测试文案
Study Notes
Note enctype this argument, as I use that multipart/form-data
, but the actual parsing it found that although the Chinese can show similar results:
But there are other questions:
- the body more than the specified delimiter, such as shape
------WebKitFormBoundarySUFFIX
, wherein each of the first post,SUFFIX
will change - If you have content, body will be more than a
Content-Disposition: form-data;
In fact, this is a question about the http protocol processing, I have no further information. I find this blog finishing very concise.