问题救助描述:
我用AXL构造了一个SPATIALQUERY,返回字段中有一字段值是中文的(如BUILDLOC),但是我取得的是乱码。我查询的代码是:
Dim arcimsRequest As HttpWebRequest = CType(WebRequest.Create(_serverURL), HttpWebRequest)
arcimsRequest.Method = "POST"
arcimsRequest.ContentType = "application/x-www-form-urlencoded"
arcimsRequest.Timeout = _requestTimeout
Dim postWriter As StreamWriter = New StreamWriter(arcimsRequest.GetRequestStream())
postWriter.Write("<?xml version='1.0' encoding='UTF-8'?>")
postWriter.Write("<ARCXML version='1.1'>")
postWriter.Write(request.AXL)
postWriter.Write("</ARCXML>")
postWriter.Flush()
postWriter.Close()
arcimsRequest.Timeout = 100000 '100秒
Dim arcimsResponse As HttpWebResponse = CType(arcimsRequest.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(arcimsResponse.GetResponseStream, System.Text.Encoding.Default)
Try
response = sr.ReadToEnd()
Finally
sr.Dispose()
End Try
查了其返回的XML中头一句中有"encoding='GBK'"
我的环境是:WIN2003 SERVER 中文版,ORA 9i ZHS16GBK,IMS 9.2
且使用BUILDLOC显示的中文标注是对的。
另:在请求中,可不可以设置ARCIMS返回的XML的encoding?
问题解决方案:
经过2天的测试,发现竟然是因为ARCIMS92 Serverlet Connector对请求的AXL中单引号处理出错所致!原来这些代码在IMS90中是运行好好的。
最后处理:
Dim strAXL As String = request.AXL
If Not String.IsNullOrEmpty(strAXL) Then 'XML正则化,可以防止返回因请求导致的中文乱码
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(strAXL)
If doc.DocumentElement Is Nothing Then
Throw New NullReferenceException("Node not set to instance of an object. Can not parse AxlFragment.")
End If
strAXL = doc.DocumentElement.OuterXml
End If
Dim strRequest As String = "<?xml version=""1.0"" encoding=""UTF-8""?><ARCXML version=""1.1"">" & strAXL & "</ARCXML>"
让XmlDocument去正则化一次请求的AXL,这样就正常了。