V
V
vladimirchelyabinskiy2016-07-26 11:49:37
C++ / C#
vladimirchelyabinskiy, 2016-07-26 11:49:37

How to get values ​​from a GET request and output them to the console?

A GET request comes to my C# server

GET /index.html?id1=1&id2=2&id3=3&id4=4 HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4

I need to output to the console all values ​​after id*=
To get the following Console.WriteLine("1 2 3 4");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AcidBat, 2016-07-26
@vladimirchelyabinskiy

Is there a similarity to the Request class, like in ASP.NET? You can output through it.
Or it is stupidly possible to parse the first line of this request.

string n = "GET /index.html?id1=1&id2=2&id3=3&id4=4 HTTP/1.1";
string q = n.Split(new Char[] { ' ', '?' })[2];
foreach(string p in q.Split(new Char[] { '&' }))
{
    System.Console.Write(p.Split(new Char[] { '=' })[1]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question