Proper data format when sending form data from client to server

1 answer

I'm confused as to how I should be sending form data from a React front-end form to a .NetCore Entity Framework controller.

It seems I either get a 400 or a 415 error.

Here is how I am sending the data in my front-end:

axios({         method: "POST",         url: "https://localhost:44376/api/formdata",         data: JSON.stringify(values),         headers: { 'Content-Type': 'application/json; charset=utf-8' } }); 

And here is how I'm recieving it:

[HttpPost] public async Task<ActionResult> AcceptContractor([FromBody] CreateContractor data) { .. } 

And here is what the data looks like written out to the console in Chrome:

{   "jobIds": [     0,     "2",     "3"   ],   "email": "",   "name": "Jim Smith",   "phone": "100-200-3000",   "jobType": "Residential",   "title": "July Jobs",   "startDate": "2020-07-23T15:50:29.345Z",   "finishDate": "2020-09-03T04:00:00.000Z" } 

I'm wondering maybe I shouldn't be using 'FromBody'?


All answers to this question, which has the identifier 60817509

The best answer:

Test this curl in postman :

curl --location --request POST 'https://localhost:44376/api/formdata' \ --header 'accept: */*' \ --header 'Content-Type: application/json-patch+json' \ --data-raw '{     "jobIds": [         "0",         "2",         "3"     ],     "email": "",     "name": "Jim Smith",     "phone": "100-200-3000",     "jobType": "Residential",     "title": "July Jobs",     "startDate": "2020-07-23T15:50:29.345Z",     "finishDate": "2020-09-03T04:00:00.000Z" }' 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type is referenced as an interface from”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data