zoukankan      html  css  js  c++  java
  • ARCIMS Serverlet Connector查询属性,当属性为中文时乱码处理

    问题救助描述:
    我用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,这样就正常了。

  • 相关阅读:
    cond
    示例:字串代换
    char char=
    (1+ val)
    UNIX通用系统变量和shell命令行参数(转)
    为python安装numpy和scipy(federo)
    浅谈HTTP中Get与Post的区别(转)
    JSON学习笔记
    javascript 实现圆角,兼容ie
    Dangling pointers and Wild pointers
  • 原文地址:https://www.cnblogs.com/Render/p/1308034.html
Copyright © 2011-2022 走看看