简体   繁体   English

如何使用在Content-Type标头中同时具有“ application / x-www-form-urlencoded”和“ charset = UTF-8”的Javascript发布HTML表单

[英]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

I need to be able to specify using Javascript how to post a form that contains both the enctype as "application/x-www-form-urlencoded" and charset as "charset=UTF-8" in the Content-Type header. 我需要能够使用Javascript指定如何在Content-Type标头中发布同时包含enctype作为“ application / x-www-form-urlencoded”和charset作为“ charset = UTF-8”的表单。 Any ideas? 有任何想法吗?

I have a aForm object of type Form. 我有一个Form类型的aForm对象。

Thanks! 谢谢!

Last I checked, you simply can't rely on being told the charset of a form submit. 最后我检查了一下,您根本不能依靠告诉表单提交的字符集。 Most sites either assume the charset (hopefully UTF-8 on modern sites) or they pass it in a separate query parameter. 大多数站点都采用字符集(希望在现代站点中为UTF-8),或者在单独的查询参数中传递字符集。

Assuming that the charset will be something in particular isn't as crazy as it sounds. 假设字符集将是特别的东西,听起来并不疯狂。 Every browser in common use will use the same encoding for submitting a form as the page that contained the form. 每个常用的浏览器都会使用与包含表单的页面相同的编码来提交表单。 So if you send the HTML page containing the form in UTF-8, you can pretty safely assume the submission will also be in UTF-8. 因此,如果您以UTF-8格式发送包含表单的HTML页面,则可以很安全地假定提交内容也将以UTF-8格式提交。

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

"application/x-www-form-urlencoded" and utf-8 cannot be used together.I too had "application/x-www-form-urlencoded", While accepting request in doPost method of servlet try request.setCharacterEncoding("UTF-8"); “ application / x-www-form-urlencoded”和utf-8不能同时使用。我也有“ application / x-www-form-urlencoded”,但是在servlet的doPost方法中接受请求时请尝试request.setCharacterEncoding(“ UTF -8“); worked for me for multilingual characters after much searching 经过大量搜索后为我工作的多语言字符

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported "ajax、setRequestHeader()、Content-Type、application\/x-www-form-urlencoded 和 charset" - ajax, setRequestHeader(), Content-Type, application/x-www-form-urlencoded and charset 使用 apollo-datasource-rest 库将 Content-Type 标头设置为 application/x-www-form-urlencoded - Setting Content-Type header to application/x-www-form-urlencoded using apollo-datasource-rest library 使用 x-www-form-urlencoded content-type 将嵌套的 object 作为 formdata 发布 - post nested object as formdata using x-www-form-urlencoded content-type “axios.defaults.headers.common['Content-Type'] = 'application/json'” 但 axios.post 仍然是“application/x-www-form-urlencoded” - "axios.defaults.headers.common['Content-Type'] = 'application/json'" but axios.post still is "application/x-www-form-urlencoded" file_get_contents():假设应用程序/x-www-form-urlencoded 未指定内容类型 - file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded 如何在+呼叫后内容类型中转义+作为application / x-www-form-urlencoded - How to escape + in post call content type as application/x-www-form-urlencoded 无法通过“Content-Type”发送 JSON object:“application/x-www-form-urlencoded - Unable to send JSON object over “Content-Type”: "application/x-www-form-urlencoded 使用字符串作为请求正文时,为什么 Axios 发送我的 POST 请求时使用 Content-Type application/x-www-form-urlencoded? - Why does Axios send my POST request with Content-Type application/x-www-form-urlencoded when using a string as the request body? 如何使用应用程序 / x-www-form-urlencoded 发送 axios 帖子? - How to send axios post with application / x-www-form-urlencoded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM