Request.Params to String提供不完整的数据

时间:2013-04-08 21:41:24

标签: c# asp.net character-encoding

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

我向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>

即。与原始xml(AAAAAAC + 5EA =)

不同,第二个ID标签(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();
      }

      ..........

1 个答案:

答案 0 :(得分:1)

  

如何解决此问题?

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