Append values to query string

I have set of URL’s similar to the ones below in a list

  • http://somesite.com/backup/lol.php?id=1&server=4&location=us
  • http://somesite.com/news.php?article=1&lang=en

I have managed to get the query strings using the following code:

myurl = longurl.Split('?');
NameValueCollection qs = HttpUtility.ParseQueryString(myurl [1]);

foreach (string lol in qs)
{
    // results will return
}

But it only returns the parameters like
id, server, location and so on based on the URL provided.

What I need is to add / append values to the existing query strings.

For example with the URL:

http://somesite.com/backup/index.php?action=login&attempts=1

I need to alter the values of the query string parameters:

action=login1

attempts=11

As you can see, I have appended “1” for each value. I need to get a set of URL’s from a string with different query strings in them and add a value to each parameter at the end & again add them to a list.

8 Answers
8

Leave a Comment