Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse through POST

I use Stream reader to read context.Request.InputStream to the end and end up with a string looking like

"Gamestart=true&GamePlayer=8&CurrentDay=Monday&..."

What would be the most efficent/"clean" way to parse that in a C# console?

like image 410
Max0999 Avatar asked May 03 '26 16:05

Max0999


2 Answers

You can use HttpUtility.ParseQueryString

Little sample:

string queryString = "Gamestart=true&GamePlayer=8&CurrentDay=Monday"; //Hardcoded just for example
NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);

foreach (String k in qscoll.AllKeys)
{
    //Prints result in output window.
    System.Diagnostics.Debug.WriteLine(k + " = " + qscoll[k]);
}
like image 75
Leri Avatar answered May 06 '26 06:05

Leri


HttpUtility.ParseQueryString

Parses a query string into a NameValueCollection using UTF8 encoding.

http://msdn.microsoft.com/en-us/library/ms150046.aspx

like image 35
Jakub Konecki Avatar answered May 06 '26 04:05

Jakub Konecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!