2013-04-08 55 views
0

不知道這是一個字符編碼的問題Request.Params到字符串給不完整的數據

我做了一個POST請求一個asp.net頁面,我發送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(); 
     } 

     .......... 

回答

1

我怎樣才能解決這個問題?

你爲什麼用HttpUtility.UrlDecode?它是XML,而不是URL! 只要你使用POST request你不需要HttpUtility.UrlDecode

+0

你是對的,首先我正在執行一個GET請求,然後我改變爲POST,並且我忘記停止使用HttpUtility.UrlDecode,這使得伎倆,謝謝 – 2013-04-08 21:59:25

+0

@NatyBizz不客氣! – 2013-04-08 22:00:25