从 AppEngine TaskQueue 服务调用的 HTTP POST 正文的编码是什么?
如果我通过 TaskOptions#payload(byte[], String)
,HTTP请求体的编码是什么?
同样,通过 TaskOptions#param(String, byte[])
并通过 ServletRequest#getParameter(String)
?
更新:我必须使用字符集名称是什么
req.getParameter("myParam").getBytes(charset)
来取回我通过 TaskOptions#param(String, byte [])
?
它似乎是 servlet 容器特定的默认值,在 http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 -- 因为所有这些都已在 servlet API 中抽象出来。
What is the encoding of a HTTP POST body called from the AppEngine TaskQueue service?
If I create a task via TaskOptions#payload(byte[], String)
, what will the encoding of the HTTP request body be?
Similarly, what will be the encoding of the String
created via TaskOptions#param(String, byte[])
and retrieved via ServletRequest#getParameter(String)
?
UPDATE: What is the charset name I have to use in
req.getParameter("myParam").getBytes(charset)
to get back the binary data I've submitted via TaskOptions#param(String, byte[])
?
It seems to be a servlet-container specific default value which is not defined in the definition for 'application/x-www-form-urlencoded' at http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 -- because all that is abstracted away in the servlet API already.
发布评论
评论(2)
没有编码 - 您传入的字节数组将成为 HTTP 请求的文字正文。
参数使用 formencoding 进行编码,就像在常规 GET 或 POST 请求中一样。
There is no encoding - the byte array you pass in becomes the literal body of the HTTP request.
Parameters are encoded using formencoding, as in a regular GET or POST request.
对于第一个,我不知道。不过,我会押注于
UTF-8
,因为 Javadoc 到处都提到了UTF-8
。您可以使用 Fiddler2 等 HTTP 调试器工具来调试请求正文。您可以使用带有 UTF-8 特定字符的字符串进行测试,这些字符通过 string.getBytes("UTF-8") 转换为字节数组,然后在 servlet 端读取它。如果它返回相同的字符,那么它使用 UTF-8 的可能性肯定很大。对于第二个,这取决于
Content-Type
请求标头中的charset
属性。然而,这种情况通常不存在(至少在使用普通网络浏览器时)。但是,您可以通过ServletRequest#setCharacterEncoding()
在访问请求正文中的任何数据之前。否则,将使用平台默认值,如
Charset#defaultCharset()
。On the first one, I have no idea. I'll however do a bet on
UTF-8
since the Javadoc mentionsUTF-8
everywhere. You could debug the request body by a HTTP debugger tool like Fiddler2. You could test around with strings with UTF-8 specific characters which are transformed to byte array bystring.getBytes("UTF-8")
and then read it in the servlet side. If it returns the same characters, then the chance is definitely big that it is using UTF-8.On the second one, that depends on the
charset
attribute in theContent-Type
request header. This is however more than often absent (at least, when a normal webbrowser is used). You can however set it yourself byServletRequest#setCharacterEncoding()
before you access any data from the request body.Otherwise the platform default one will be used, as specified by
Charset#defaultCharset()
.