简体   繁体   中英

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. Any ideas?

I have a aForm object of type Form.

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.

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.

尝试.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"); worked for me for multilingual characters after much searching

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM