程序是这样的:asp+xmlhttp:功能是:用xmlhttp+soap抓取数据并实时更新数据库、、
在本机测试(开发环境:asp+mysql:)一切正常、、
但在上传到服务器(英文操作系统)时、、post数据得到返回值、、在存入数据库时、、显示为乱码、、
以下为源程序:
<%
Dim str,zoneIdArr,zoneNameArr
Function getXMLInf(xmlStr) '读取返回的XML格式的数据
getXMLInf=""
If xmlStr="" Then
Exit Function
Else
'----------得到返回中字符中的XML字符--->以XML格式解析字符
xmlStr=Replace(Replace(xmlStr,"<"," <"),">",">")
xmlStr=Mid(xmlStr,InStr(xmlStr," <?xml"))
xmlStr=Left(xmlStr,InStr(xmlStr," </servers>")+9)
Set xmlDom=server.CreateObject("Microsoft.xmlDom")
xmlDom.async=False
xmlDom.validateOnParse=True
xmlDom.loadXML(xmlStr)
Set xmlRoot=xmlDom.documentElement
For i=0 To xmlRoot.childNodes.length-1
If i=xmlRoot.childNodes.length-1 Then
zoneIdArr=zoneIdArr&xmlRoot.childNodes(i).getAttribute("id")
zoneNameArr=zoneNameArr&xmlRoot.childNodes(i).getAttribute("name")
Else
zoneIdArr=zoneIdArr&xmlRoot.childNodes(i).getAttribute("id")&","
zoneNameArr=zoneNameArr&xmlRoot.childNodes(i).getAttribute("name")&","
End If
Next
Set xmlDom=Nothing
End If
End Function
Function getZoneXmlByGameType(intGameType) '得到游戏区zoneId
strUrl = "https://esales.wanmei.com/e/services/UseCardManage"
SoapRequest=" <?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
" <soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
" <soap:Body>"& _
" <getZoneXmlByGameType xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _
" <GameType>"&intGameType&" </GameType>"& _
" </getZoneXmlByGameType>"& _
" </soap:Body>"& _
" </soap:Envelope>"
Set xmlhttp = server.CreateObject("WinHttp.WinHttpRequest.5.1")
xmlhttp.Open "POST",strUrl,false
xmlhttp.Option(4) = 13056
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/LoginByAccount"
xmlhttp.Send SoapRequest
Set xmlDOC =server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseBody)
strBody = xmlDOC.xml '此句在本机下为正常、、在服务器上为乱码:只要是中文的就全是“????”
Set xmlDOC=nothing
Set xmlhttp = Nothing
getZoneXmlByGameType=getXMLInf(strBody)
End Function
For j=1 To 5
If j=1 Then
card_id=434 '完美世界
ElseIf j=2 Then
card_id=407 '武林外传
ElseIf j=3 Then
card_id=414 '完美国际版
ElseIf j=4 Then
card_id=490 '诛仙
ElseIf j=5 Then
card_id=476 '赤壁
End If
str=getZoneXmlByGameType(j)
If InStr(zoneIdArr,",")>0 And InStr(zoneNameArr,",")>0 Then
zoneIdArr=Split(zoneIdArr,",")
zoneNameArr=Split(zoneNameArr,",")
'---------锁定表更新数据
conn.execute "lock tables charge_option write"
conn.execute "delete from charge_option where card_id="&card_id
For k=LBound(zoneIdArr) To UBound(zoneIdArr)
conn.execute "insert into charge_option(card_id,option_number,option_value,option_name) values("&card_id&",1,'"&zoneIdArr(k)&"','"&zoneNameArr(k)&"')"
Next
conn.execute "unlock tables "
'---------锁定表更新数据
End If
zoneIdArr=""
zoneNameArr=""
Next
response.write "更新完毕"
%>
post请求时是utf-8、、得到返回值是gb2312的XML
后来google、、也没找到原因、、
自己尝试了以下方法、、都失败了、、、
1.首先想到就是编码问题、、用
Function BytesToBstr(body)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312"
'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
将xmlDOC.load(xmlhttp.responseBody)
------>改成xmlDOC.load(BytesToBstr(xmlhttp.responseBody))、、、失败、、
2.想到可能是两个操作系统下建立的表的环境不同、、于是删除在服务器上建立的表、、将本机上的表的结构直接导入服务器上、、也不成功、、
在线等、、晕大了、、