2013-04-10 37 views
3

我試圖解析string ResponseNameValueCollection如下所示:必須使用http:// 1 /?在新的URI()爲了得到NameValueCollection中

public static NameValueCollection Request() 
{ 
    // Snipped irrelevant code, so here's the string I get: 
    string Response = "someparam=abcdef&another=123456"; 

    return HttpUtility.ParseQueryString(
     new Uri("http://1/?" + Response) 
    .Query); 
} 

NameValueCollection Request = SomeClass.Request(); 
string SomeParam = Request.Get("someparam"); 
string Another = Request.Get("another"); 

但似乎「錯誤」對我來說,必須指定http://1/?(一UriFormatException是扔沒有它)。

有沒有不同的方法我應該接近這個?

回答

6

這裏沒有理由讓您使用Uri,只需HttpUtility.ParseQueryString(Response)應該做的。

+0

這很好,謝謝! – 2013-04-10 23:08:07

相關問題