我正在上传一个包含文件、文本等内容的表单到appengine blobstore:
$http({
method: 'POST',
url: the_url,
transformRequest: formDataObject,
data: event,
headers: {'Content-Type': undefined}
})请求成功发送,报头如下:
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryYeRxOO7y3qHNWd83当我尝试将content-type设置为"multipart/form-data;charset=UTF-8"时,我丢失了边界并在响应中得到错误:Bad content type. Please use multipart.
添加UTF-8字符集的正确方法是什么?
发布于 2013-12-09 09:45:17
根据RFC 1341:
As stated in the definition of the Content-Transfer-Encoding field, no encoding other than "7bit", "8bit", or "binary" is permitted for entities of type "multipart". The multipart delimiters and header fields are always 7-bit ASCII in any case, and data within the body parts can be encoded on a part-by-part basis, with Content-Transfer-Encoding fields for each appropriate body part.
因此,在这种情况下,您必须使用Content-Transfer-Encoding而不是Content-Type。
发布于 2013-12-10 05:37:42
我的解决方案是不改变任何东西:
事实证明,使用headers: {'Content-Type': undefined}是正确的。现在一切都正常了(我只改变了后端)。
问题是webob忽略了编码,因此我认为编码是错误的。升级webob解决了此问题。之所以很难检测到这一点,是因为开发服务器默认使用新的webob,而产品默认使用较旧的webob版本,因为新版本没有在app.yaml中指定:
libraries:
- name: webob
version: "1.2.3"发布于 2017-07-04 17:03:05
字符集必须进行如下设置: Content-Type:multipart/form-data;boundary=----WebKitFormBoundaryYeRxOO7y3qHNWd83;charset=UTF-8
https://stackoverflow.com/questions/20461594
复制相似问题