What is the encoding used by AppEngine TaskQueue when they encode byte[] arrays as Strings?
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.
If I create a task via TaskOptions#payload(byte[], String), what will the encoding of the HTTP request body be?
There is no encoding - the byte array you pass in becomes the literal body of the HTTP request.
Similarly, what will be the encoding of the String created via TaskOptions#param(String, byte[]) and retrieved via ServletRequest#getParameter(String)?
Parameters are encoded using formencoding, as in a regular GET or POST request.
On the first one, I have no idea. I'll however do a bet on UTF-8
since the Javadoc mentions UTF-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 by string.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 the Content-Type
request header. This is however more than often absent (at least, when a normal webbrowser is used). You can however set it yourself by ServletRequest#setCharacterEncoding()
before you access any data from the request body.
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
Otherwise the platform default one will be used, as specified by Charset#defaultCharset()
.
精彩评论