Home > Net >  The core asp.net Web API how to directly access the content in the body
The core asp.net Web API how to directly access the content in the body

Time:03-19

Need a WEB API interface, directly from the request to read the string data in the body, content and format string, and casual, very random, is not formatted form

With public dynamic f ([RequestBody] string content) can't get

CodePudding user response:

 
Public void UserLoginbyLoginName ([FromBody] JsonElement body) {
Var jsonParms=PostBody (body);
}
Private static dynamic PostBody (JsonElement body) {
String json=System. Text. Json. JsonSerializer. Serialize (body);
Return JsonConvert. DeserializeObject (json);
}

CodePudding user response:

The
reference 1/f, hands on the keyboard to knock very light response:
 
Public void UserLoginbyLoginName ([FromBody] JsonElement body) {
Var jsonParms=PostBody (body);
}
Private static dynamic PostBody (JsonElement body) {
String json=System. Text. Json. JsonSerializer. Serialize (body);
Return JsonConvert. DeserializeObject (json);
}


What I want is a string, the string in the body is very random, without any format

CodePudding user response:

Put one into the case, what's request header, and content in the body

CodePudding user response:

The core is not clear... If it is webapi [FromBody] string STR directly.
  •  Tags:  
  • C#
  • Related