【问题标题】:How to post a HTML form using Javascript that has both "application/x-www-form-urlencoded" and "charset=UTF-8" in the Content-Type header如何使用在 Content-Type 标头中同时具有“application/x-www-form-urlencoded”和“charset=UTF-8”的 Javascript 发布 HTML 表单
【发布时间】:2011-01-04 10:12:22
【问题描述】:

我需要能够使用 Javascript 指定如何在 Content-Type 标头中发布包含 enctype 为“application/x-www-form-urlencoded”和字符集为“charset=UTF-8”的表单.有什么想法吗?

我有一个 Form 类型的 aForm 对象。

谢谢!

【问题讨论】:

  • 那么事情进展如何?已经有一段时间了。

标签: javascript forms post character-encoding enctype


【解决方案1】:

“application/x-www-form-urlencoded”和utf-8不能一起用。我也有“application/x-www-form-urlencoded”, 在 servlet 的 doPost 方法中接受请求时,请尝试 request.setCharacterEncoding("UTF-8");经过大量搜索后为我工作了多语言字符

【讨论】:

    【解决方案2】:

    试试.setRequestHeader( 'content-type', 'application/x-www-form-urlencoded;charset=UTF-8' );

    【讨论】:

      【解决方案3】:

      上次我检查过,您根本不能依赖被告知表单提交的字符集。大多数网站要么采用字符集(希望在现代网站上使用 UTF-8),要么在单独的查询参数中传递它。

      假设字符集是特别的东西并不像听起来那么疯狂。每个常用的浏览器都将使用与包含表单的页面相同的编码来提交表单。因此,如果您以 UTF-8 格式发送包含表单的 HTML 页面,您可以非常安全地假设提交也将采用 UTF-8 格式。

      【讨论】:

      • 感谢您的回复。问题是当我将它发送到服务器时,我将它作为“application/x-www-form-urlencoded”发送,但在服务器端,它被更改为“text/plain”,所以我需要确保在服务器端它保持为 'application/x-www-form-urlencoded' 并且字符集是 UTF-8。
      • 顺便说一下,我正在使用表单对象。谢谢!
      猜你喜欢
      • 2013-11-10
      • 1970-01-01
      • 2019-02-04
      • 2019-05-24
      • 2018-05-12
      • 2019-06-14
      • 2018-06-20
      • 1970-01-01
      • 2019-02-20
      相关资源
      最近更新 更多