I just tried with mattermost-preview docker image Mattermost Version: 9.5.0. The same.
curl --location 'http://localhost:8065/api/v4/posts' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer hfayeezxm3yuumro9xok7ju7uy' \
--data '{
"channelId": "mwrwoefugpnfiqhu9ut4zjo3xw",
"message": "Hello world"
}'