• 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,这样就正常了。

  • 相关阅读:
    ORM框架工具产品开发之四 开发代码生成器 Template Studio Development (一)
    信息化基础建设系列文章汇总 .NET 平台业务项目实践
    NodeJs:基于Provider模式的推送服务器实现
    Javascript:用 "脑图软件" 学习 “面向对象”
    TDD:MS自带的单元测试 之 线程模型和执行顺序
    NodeJs:“require” 函数详解,懂这个你就懂NodeJs了
    ExtJS4.2:AJAX提交数据的三种方式,80%人都没用过第三种
    设计原则:为什么需要“IOC”
    算法:“森林的遍历” 在 “企业应用” 的常见场景
    .NET:自动将请求参数绑定到ASPX、ASHX和MVC(菜鸟必看)
  • 原文地址:https://www.cnblogs.com/Render/p/1308034.html
Copyright © 2020-2023  润新知