Home > Net >  C # how to format the json below post sent to the server
C # how to format the json below post sent to the server

Time:12-03

{
"Dvsid" : "12345678123456781234567812345678",
"UserId", "r00002",
"Date" : "2020/11/25,"
"A list" : [
{
"ClockStyle" : "0",
"ClockTime" : "2020/11/25 08:37:24"
}
]
}

Dynamic Settings in which these values are not dead, such as userId=textbox. The text is based on the value of the input box to preach,

CodePudding user response:

Put these into a byte [], and then submit the byte [] array

CodePudding user response:

reference 1st floor gs0038 response:
put these into a byte [], and then submit the byte [] array
Emmm,, can I bother you write specific

CodePudding user response:

Json string directly as the Request. The Body line ah, head and instruct the content-type=application/json,

CodePudding user response:

The json building a class first, then various attributes of the class instance editor, then serialized into a json string, and then send data - usually look like
Can also use ${variable} "the string interpolation syntax to modify the json data - lazy, do not recommend
As to how to send a post request, recommend you use a postman, this simple to learn, use tools, after debugging interface directly can export all kinds of successful language example code.

CodePudding user response:

//get request data
Var value=https://bbs.csdn.net/topics/data==null? String. The Empty: JsonConvert. SerializeObject (data);
//to encapsulate all the HTTP specific information about the individual HTTP requests (context)
Var content=new StringContent (value, Encoding UTF8);
//set the context of a request header type
Content. The Headers. ContentType=new MediaTypeHeaderValue (" application/json ");

//send Post asynchronous request information
Using (var client=new HttpClient ())
{
//send an asynchronous request
Var result=client. PostAsync (url, the content). The result;
//get request to return to the results of the data and its serialization for string
Var response=result. Content. ReadAsStringAsync (). The result;
If (result. StatusCode!=System.Net.HttpStatusCode.OK)
Throw new HttpRequestException ($" call interface: {url} error, StatusCode: {result. StatusCode}, Msg: {response} ");
//returns the results deserialization for a given Model
Return JsonConvert. DeserializeObject (response);
}

CodePudding user response:

reference 5 building powerful farmers reply:
//get request data
Var value=https://bbs.csdn.net/topics/data==null? String. The Empty: JsonConvert. SerializeObject (data);
//to encapsulate all the HTTP specific information about the individual HTTP requests (context)
Var content=new StringContent (value, Encoding UTF8);
//set the context of a request header type
Content. The Headers. ContentType=new MediaTypeHeaderValue (" application/json ");

//send Post asynchronous request information
Using (var client=new HttpClient ())
{
//send an asynchronous request
Var result=client. PostAsync (url, the content). The result;
//get request to return to the results of the data and its serialization for string
Var response=result. Content. ReadAsStringAsync (). The result;
If (result. StatusCode!=System.Net.HttpStatusCode.OK)
Throw new HttpRequestException ($" call interface: {url} error, StatusCode: {result. StatusCode}, Msg: {response} ");
//returns the results deserialization for a given Model
Return JsonConvert. DeserializeObject (response);
}

Ask: hello, this is what ah,,, but also an error, and note: unable to find the type or namespace ApiResult<> Unable to find the type or namespace "TResult" Alt + enter no useful solution, after that, baidu also didn't look up to
  •  Tags:  
  • C#
  • Related