Read the http object and put it in variables

how do you create a class to read the html body and phase it into a variable?

Example page http://domain.com/page1.aspx

display next plaintext in html body content

item1=xyz&item2=abc&item3=jkl

how do you read html body content and assign them to variables

in this case

variable1 = xyz (value taken from item1 =)

variable2 = abc (value taken from item2 =)

variable3 = jkl (value taken from item3 =)?

+3
source share
2 answers

This is step two .

First you need to get the contents of the body.

Second, you need to parse the contents and assign variables.

:

Regex exp = new Regex(@"((?:.(?!<body[^>]*>))+.<body[^>]*>)|(</body\>.+)", RegexOptions.IgnoreCase);
string InputText = content;

string[] MatchList = exp.Split(InputText);
string body = MatchList[2];

:

        string body = content;
        string [] param = {"&"};
        string[] anotherParam = { "=" };
        string[] str = body.Split(param , StringSplitOptions.RemoveEmptyEntries);
        System.Collections.Hashtable table = new System.Collections.Hashtable();
        foreach (string item in table)
        {
            string[] arr = item.ToString().Split(anotherParam, StringSplitOptions.RemoveEmptyEntries);
            if(arr.length != 2)
                 continue;
            if(!table.Contains(arr[0])){
                table.Add(arr[0], arr[1]);
            }                
        }
+1

, , html. ASP.NET Context

string var1 = Context.Request.QueryString["item1"];
+1

Source: https://habr.com/ru/post/1736060/


All Articles