I want to slap a simple class together to pick out QueryString variables from an HTTP request that gets sent to my application. The variables are not always in the same order, but they're always there. I want to assign the variables in my class the values of the corresponding variables from the request, but I have no idea how to do this.
Code snippets:
MyHTTPRequest ar = new MyHTTPRequest("GET /submit.php?variableOne=value&variableTwo=someothervalue HTTP/1.1"); // Leaving out the rest for now
class MyHTTPRequest
{
public string variableOne;
public string variableTwo;
public string variableThree;
private string[] properties = { "variableOne", "variableTwo", "variableThree" }; // I know they're not actually properties
public MyHTTPRequest(string request)
{
string[] variablePars = request.Substring(16, request.Length - 24).Split('&'); // variablePars now contains "variableOne=value" & "variableTwo=someothervalue"
foreach (string variablePar in variablePars)
{
if (properties.Contains(variablePar.Split('=')[0])) // variableOne, variableTwo, variableThree
{
// Assign the correct variable the value
<???> = variablePar.Split('=')[1]; // I don't know how to pull this one off. variablePar.Split('=')[0] should contain the name of the variable.
}
}
}
}
Any input?
I'm sure a similar question already exists, but I did not know what to titel or tag this with.