cli: Invalid Content-Type for Netlify Dev forms request
Describe the bug
When running Netlify Functions locally via netlify dev and making a POST request to a function endpoint, I’m getting the following console error:
Invalid Content-Type for Netlify Dev forms request
To Reproduce
Steps to reproduce the behavior:
- Generate a new netlify function using
netlify functions:create hello-world - Pick
[hello-world]template - Serve newly created function locally with
netlify dev - Make request to local function endpoint (using Postman, curl etc…)
- Set method to
POST - Add header:
Content-Type: applications/json
- Set method to
- Response will contain
Invalid Content-Type for Netlify Dev forms requesterror
Configuration
Using netlify-cli@2.64.1.
netlilfy.toml:
[build]
functions = "functions"
envinfo:
System:
OS: macOS 10.15.6
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 183.36 MB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
Yarn: 1.22.5 - ~/.nvm/versions/node/v12.18.2/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v12.18.2/bin/npm
Expected behavior
No error.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 15
- Comments: 17 (6 by maintainers)
FWIW I was getting the same error “Invalid Content-Type for Netlify Dev forms request” when my POST url was of the form:
http://localhost:<port>/exampleIt works after I corrected that url per @erezrokahhttp://localhost:<port>/.netlify/functions/exampleThanks!Re-opened the issue per https://github.com/netlify/cli/issues/1279#issuecomment-785981336. @hwlmatt please note that the reproduction in that repo is different - you’re not sending the request to the function endpoint.
http://localhost:<port>/exampleshould behttp://localhost:<port>/.netlify/functions/example@erezrokah Sure thing. This reproduces it for me. README has the steps & cURL command etc.
https://github.com/hwlmatt/netlify-cli-issue.git
This is actually quite shocking. POST is critical to almost any RESTful API and from what I’m seeing I can send a request via GET, PUT, DELETE, etc. and it all works as expected. Using POST however returns the
Invalid Content-Type for Netlify Dev forms requestmessage to the node server console.To this point, my testing has been within the
netlify devsandbox. Will try in a post-deploy environment soon too but for testing purposes it really needs to work in both environments anyway.