0

不知道是不是字符编码问题

我向 asp.net 页面发出了 POST 请求,我发送了一个 XML,以便将值放入我制作的变量中

String selectionXml = HttpUtility.UrlDecode(Request.Params["SELECTION"]);

这是我的xml的一个例子

<?xml version="1.0" encoding="UTF-8"?>
<FeatureSet>
<Layer id="0adcf012">
<Class id="MyTable">
<ID>AAAAAAAmvEA=</ID>
<ID>AAAAAAC+5EA=</ID>
</Class>
</Layer>
</FeatureSet>

问题是,当我执行上述句子时,我得到了这个 xml

<?xml version="1.0" encoding="UTF-8"?>
<FeatureSet>
<Layer id="0adcf012">
<Class id="MyTable">
<ID>AAAAAAAmvEA=</ID>
<ID>AAAAAAC 5EA=</ID>
</Class>
</Layer>
</FeatureSet>

即第二个 ID 标签 (AAAAAAC 5EA=) 出现时没有加号 (+) 与原始 xml (AAAAAAC+5EA=) 不同

我该如何解决这个问题?

编辑:我添加了更多代码,这是我的 asp.net 页面(使用 mapguide 库)

<%@ Page Language="C#" Debug="true" validateRequest="false"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="OSGeo.MapGuide" %>

<!-- #Include File="common.aspx" -->
<%

    Response.Charset = "utf-8";
    String sessionId;
    String mapName;
    String locale;
    int target=0;
    int popup=0;
    String selectedLayer;
    MgSelection selection = null;
    sessionId = Request.Params["SESSION"];
    mapName = Request.Params["MAPNAME"];
    locale = Request.Params["LOCALE"];
    target = int.Parse(Request.Params["TGT"]);
    popup = int.Parse(Request.Params["POPUP"]);
    selectedLayer = Request.Params["LAYERTARGET"];

    bool todos = false;
    try
    {

      // Initialize the Web Extensions and connect to the Server using
      // the Web Extensions session identifier stored in PHP session state.

      //MapGuideApi.MgInitializeWebTier (Constants.WebConfigPath);
      InitializeWebTier();
      MgUserInformation userInfo = new MgUserInformation(sessionId);
      MgSiteConnection siteConnection = new MgSiteConnection();
      siteConnection.Open(userInfo);

      MgMap map = new MgMap(siteConnection);
      map.Open(mapName);

      // ----------------------------------------------------------
      // Use the following code for AJAX or DWF Viewers
      // This requires passing selection data via HTTP POST

      MgReadOnlyLayerCollection layers = null;
      **String selectionXml = HttpUtility.UrlDecode(Request.Params["SELECTION"]);**
      if (selectionXml!= null)
      {
        selection = new MgSelection(map, selectionXml);
        layers = selection.GetLayers();
      }

      ..........
4

1 回答 1

1

我该如何解决这个问题?

你为什么用HttpUtility.UrlDecode?它是 XML,而不是 URL!只要您正在使用POST request,您就不需要HttpUtility.UrlDecode.

于 2013-04-08T21:51:50.633 回答