How do I set the character set using XMLHttp Object for a POST in classic ASP?

浪子不回头ぞ 提交于 2019-12-07 15:46:26

问题


I have to use the XMLHttp object in classic ASP in order to send some data to another server via HTTP from server to server:

sURL = SOME_URL

Set oXHttp = Server.CreateObject("Msxml2.XMLHTTP")

oXHttp.open "POST", sURL, false 
oXHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset:ISO-8859-1;"

sPost = SOME_FORM_DATA

oXHttp.send(sPost)

I've been told (by the maintainer of the consuming server) that, depending on whether I use this code from Windows Server 2000 (IIS 5) or Windows Server 2003 (IIS 6), he gets Latin-1 (Windows 2000 Server) or UTF-8 (Windows Server 2003) encoded data.

I didn't find any property or method to set the character set of data I have to send. Does it depend on some Windows configuration or scripting (asp) settings?


回答1:


You can set the codepage used by setting the option 'SXH_OPTION_URL_CODEPAGE'

http://msdn.microsoft.com/en-us/library/ms763811(VS.85).aspx

You should also be using the 'MSXML2.ServerXMLHTTP' object not the 'MSXML2.XMLHttp' object which is for single threaded client side apps.




回答2:


The answer above referring to SXH_OPTION_URL_CODEPAGE is kind of misleading. That option is not related to the encoding of the request body, which I think the question was about.

The problem with the code example in the question is the use of ":" instead of "=" in the header. It should be set as follows:

oXHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1"



来源:https://stackoverflow.com/questions/190988/how-do-i-set-the-character-set-using-xmlhttp-object-for-a-post-in-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!