2012-08-17 99 views
0

樣本數據URL從查詢參數獲取URL

_http://abc.com/cache.ashx?feedURL=http://search.twitter.com/search.rss?q=from%3AAbbottNews&rpp=3&clientsource=TWITTERINC_WIDGET&include_entities=true&result_type=recent&1334673762143=cachebust 

我試圖讓FeedURL以下是我所得到的查詢參數的值;

實際:http://search.twitter.com/search.rss?q=from%3AAbbottNews&rpp=3&clientsource=TWITTERINC_WIDGET&include_entities=true&result_type=recent&1334673762143=cachebust

什麼我越來越:http://search.twitter.com/search.rss?q=from%3AAbbottNews

要求:我需要的完整的URL。

注:它從第二個參數開始

骯髒的解決方案截斷:
我嘗試了所有的建議,但我覺得有沒有更好的解決辦法。沒有其他的去,我做了一個骯髒的解決方案,以完全獲得URL的正確部分。

/// <summary> 
/// Get Feed URL from raw URL 
/// </summary> 
/// <param name="rawURL"></param> 
/// <returns></returns> 
public static string GetFeedURL(string rawURL) 
{ 
    int index = rawURL.IndexOf("="); 
    string _rawURL = rawURL; 

    if (index > 0) 
     _rawURL = _rawURL.Substring(index).Remove(0, 1); 

    return _rawURL; 
} 
+1

你可以發佈任何代碼,你實際上在做什麼?你的例子很混亂。 – CoderMarkus 2012-08-17 19:53:18

+0

改進了實際樣本的內容。 – 2012-08-17 20:10:08

+0

您必須編碼路徑(?和&s導致要拆分的參數)或再次連接它們 – StrubT 2012-08-17 20:12:27

回答

2

它看起來像這可能是由於在您FeedUrl第一「&」字,可以得到治療作爲外查詢字符串的查詢參數的事實。您可能需要先編碼FeedUrl。這只是我最初的直覺。

1

你需要將它們添加到URL時來urlencode您的網址變量...

url = "http://url.com?id=" + HttpUtility.UrlEncode("..."); 
Response.Redirect(url); 

..和URLDecode他們的請求後,與他們一起工作......

HttpUtility.UrlDecode(Request.QueryString["id"]); 

否則QueryString請求不知道如何處理所有額外的?和&的。

0

您提供的URL雖然有效,但不會按照您的預期解析;它會按照當前的方式進行解析。除非對&符號進行編碼,否則不支持嵌套查詢字符串。