Project scenario:
In net5.0, use httpcontext to get the post and get parameters transmitted in it
Go directly to the code:
// Get the post parameter idea: read the parameters in the body in the form of a stream
public async Task Invoke(HttpContext context)
{
HttpRequest request = context.Request;
Stream straem = request.Body;
Encoding encoding = Encoding.UTF8;
string date = string.Empty;
using (StreamReader reader = new StreamReader(straem, encoding))
{
//date就是post传过来的值json格式
date = reader.ReadToEndAsync().Result;
}
}
// get get parameters
context.Request.QueryString.Value
This sentence can be obtained, and what is read is a string example:
?userid='123'&username='Zhang San'
is such a style