如何在经典 ASP 中使用 XMLHttp 对象为 POST 设置字符集?
我必须使用经典 ASP 中的 XMLHttp 对象,以便通过 HTTP 从服务器到服务器将一些数据发送到另一台服务器:
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)
我被告知(由使用服务器的维护者),取决于无论我是在 Windows Server 2000 (IIS 5) 还是 Windows Server 2003 (IIS 6) 中使用此代码,他都会得到 Latin-1 (Windows 2000 Server) 或 UTF-8 (Windows Server 2003) 编码数据。
我没有找到任何属性或方法来设置我必须发送的数据的字符集。 它是否取决于某些 Windows 配置或脚本 (asp) 设置?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过设置选项 'SXH_OPTION_URL_CODEPAGE'
来设置使用的代码页http://msdn.microsoft.com/en-us/library/ms763811(VS.85).aspx
您还应该使用“MSXML2.ServerXMLHTTP”对象而不是“MSXML2.XMLHttp”对象对于单线程客户端应用程序。
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.
上面提到 SXH_OPTION_URL_CODEPAGE 的答案有点误导。 该选项与请求正文的编码无关,我认为问题与此有关。
问题中的代码示例的问题是在标题中使用“:”而不是“=”。 应设置如下:
oXHttp.setRequestHeader
“内容类型”,“application/x-www-form-urlencoded;字符集=ISO-8859-1”
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"