Using Reactjs with Axios to post/get to a dotnetcore webapi.
- Axios GET api call to retrieve a list of datetimesUTC
- Response datetimeUTCs are clearly correct in console/display.
- Axios GET api call passes in the selected datetimeUTC
- The API clearly receives the correct UTC datetime
- Axios POST api call passes in the same selected datetimeUTC
- The API receives localized datetime instead of the UTC time.
My issue is: Why in the world does my API get the correct UTC on a GET, but localized on a POST?
I have tried an empty controller functions, one with POST, one with GET, and can clearly see they are different.
/// API post w/ Axios
axios.post("api/action", {
date: date
});
/// API get w/ Axios
axios.get("api/action", {
params: { date: date}
});
[HttpPost("{action}")]
public void Reconcile([FromBody]DateTime date)
{
...
}
[HttpGet("{action}")]
public void Reconcile(DateTime date)
{
...
}
The GET api action receives the correct UTC datetime. The POST api action receives the incorrect, localized datetime.
EDIT:
POST
- Axios Post: date: "2019-01-01T12:00:00.000Z"
- API received: DateTime - {1/1/2019 12:00:00 PM}
GET
- Axios Get: date: "2019-01-01T12:00:00.000Z"
- API received: DateTime - {1/1/2019 5:00:00 AM}
I just cannot fathom why it changes for post/get. I didn't have to do anything fancy at all for the GET, but it's a nightmare all day trying to get the POST to work. I could just change it to a GET and it'd be fine, but semantically it really ought to be a POST.