XMLHTTP返回问题(100分)

  • 主题发起人 主题发起人 geyuan
  • 开始时间 开始时间
G

geyuan

Unregistered / Unconfirmed
GUEST, unregistred user!
我在Delphi中用XmlHttp读取数据,服务器返回的,我如何读取?
xmlhttp有
ResponseXML、ResponseText、ResponseStream、ResponseBody
我用ResponseText,但是,返回数据中有中文,为乱码?我如何处理?
这四个返回方式,我如何进行管理??
 
geyuan,搞定了吗?能否说明一下解决方法?
 
我现在用RESPONEBODY返回方式进行处理
MyVariant := SMSHttp.responseBody;
ReturnStr := '';
For i := 0 To VarArrayHighBound(MyVariant, 1) Do
ReturnStr := ReturnStr + Chr(Byte(MyVariant));
 
不知有哪位高人能解释这种情况?
 
XMLHTTP默认是使用UTF-8编码传输数据.所以中文被转换成3个字节的数据了.用适当的方式还可以解码回来.
 
我也和geyuan一样
 
XMLHTTP提交中文出现乱码问题解决方案

xwing@263.net

客户端代码
function submitSC(){
try{
var myxml = new ActiveXObject("MSXML2.DOMDocument");
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
myxml.async = false;
myxml.loadXML(scSCData.xml);
xmlHttp.open("POST", "<%=getAspURL("listSC.asp")%>sinkSCData.asp" , false);
//xmlHttp.setRequestHeader("CONTENT-TYPE","text/xml; charset = gb2312");
xmlHttp.send(myxml);
alert(xmlHttp.responseText);

}
catch (exception){
var errDes = '无法提交数据。<br>详细错误信息:"' + exception.description + '"。'
window.location.href="err.asp?errtype="+errDes; }
}

<%
function getAspURL(aspfileName)
getAspURL = "http://" &_
request.servervariables("http_host") &_
left(request.servervariables("path_info"),len(request.servervariables("path_info"))-len(aspFileName))
end function
%>

服务器端代码
方案一:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Response.ContentType = "text/xml"
Response.CharSet = "GB2312"

if Request.ServerVariables("REQUEST_METHOD") = "POST" then
dim fname,xmldoc, xmlhead

Set xmldoc = server.CreateObject("Msxml2.DOMDocument")
set xmlhead = xmldoc.createProcessingInstruction("xml","version=""1.0"" encoding=""GB2312""")
xmldoc.load(Request)

xmldoc.removeChild xmldoc.firstChild
xmldoc.insertBefore xmlhead,xmldoc.firstChild

fname = Server.MapPath(".") & "/recv.xml"
xmldoc.save(fname)
xmldoc.save(response) '回写客户端测试
end if

%>

方案二:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Response.ContentType = "text/xml"
Response.CharSet = "GB2312"
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
dim fname,xmldoc,aStream
Set xmldoc = server.CreateObject("Msxml2.DOMDocument")
set aStream = server.createobject("adodb.stream")
xmldoc.load(Request)
astream.mode = 2 'writeMode
astream.type = 2 '文本模式
astream.open
astream.charset = "gb2312"
astream.writetext "<?xml version=""1.0"" encoding=""GB2312""?>" & xmldoc.documentElement.xml
fname = Server.MapPath(".") & "/recv.xml"
astream.savetofile fname, 2
astream.close
'回写客户端测试
Response.Write "<?xml version=""1.0"" encoding=""GB2312""?>" & xmldoc.documentElement.xml
end if
%>


 
认为 xwings 的方式可行,我现在也是采用的 MSXML3 中的组件.
 
后退
顶部