You need to set your content-type to application/json. But -d
(or --data
) sends the Content-Type application/x-www-form-urlencoded
, which is not accepted on Spring’s side.
Looking at the curl man page, I think you can use -H
(or --header
):
-H "Content-Type: application/json"
Full example:
curl --header "Content-Type: application/json" \ --request POST \ --data '{"username":"xyz","password":"xyz"}' \ http://localhost:3000/api/login
(-H
is short for --header
, -d
for --data
)
Note that -request POST
is optional if you use -d
, as the -d
flag implies a POST request.
On Windows, things are slightly different. See the comment thread.
Related Posts:
- How do I POST JSON data with cURL?
- How do I POST JSON data with cURL?
- What is the correct JSON content type?
- What is the correct JSON content type?
- What is the correct JSON content type?
- How to do a PUT request with cURL?
- How to use cURL to send Cookies?
- RestClientException: Could not extract response. no suitable HttpMessageConverter found
- How to POST JSON Data With PHP cURL?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Use of PUT vs PATCH methods in REST API real life scenarios
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to send a header using a HTTP request through a cURL call?
- Getting “java.io.IOException: An existing connection was forcibly closed by the remote host”
- What’s the difference between text/xml vs application/xml for webservice response
- HTTP GET with request body
- Using Wikipedia API on custom wikis like Bulbapedia
- SON Post with Customized HTTPHeader Field
- How to upload a file and JSON data in Postman?
- PHP cURL HTTP PUT
- curl: no URL specified for restful api
- How to create a post using REST API with sending data as a JSON body?
- Why is json_decode failing?
- Is it possible to make WordPress as a RESTful app?
- Difference between `curl -I` and `curl -X HEAD`
- Why am I seeing “TypeError: string indices must be integers”?
- How to prettyprint a JSON file?
- What is the difference between POST and PUT in HTTP?
- What is the difference between POST and PUT in HTTP?
- Can comments be used in JSON?
- How to use Collections.sort() in Java?
- pandas read_json: “If using all scalar values, you must pass an index”
- Can comments be used in JSON?
- Parse JSON in JavaScript? [duplicate]
- JSON parsing error syntax error unexpected end of input
- SOAP vs REST (differences)
- Angular: ‘Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays’
- Why am I seeing “TypeError: string indices must be integers”?
- C# HttpClient An existing connection was forcibly closed by the remote host
- “SyntaxError: Unexpected token < in JSON at position 0"
- How do I get a YouTube video thumbnail from the YouTube API?
- How to parse JSON in Java
- Grabbing the current viewer count for youtube live streaming
- “SyntaxError: Unexpected token < in JSON at position 0"
- How can I parse JSON with C#?
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- curl: (60) SSL certificate problem: unable to get local issuer certificate
- HTTP POST and GET using cURL in Linux [duplicate]
- curl: (60) SSL certificate problem: unable to get local issuer certificate
- This application has no explicit mapping for /error
- SyntaxError: Unexpected token o in JSON at position 1
- What is the easiest way to convert an Excel spreadsheet with tabular data to JSON? [closed]
- Converting dictionary to JSON
- Do I need Content-Type: application/octet-stream for file download?
- SyntaxError: Unexpected token o in JSON at position 1
- What is JSONP, and why was it created?
- TypeError: Converting circular structure to JSON in nodejs
- How do I install and use cURL on Windows?
- Can comments be used in JSON?
- Is there a way to follow redirects with command line cURL?
- How to fix “SSL certificate problem: self signed certificate in certificate chain” error?
- 403 Forbidden vs 401 Unauthorized HTTP responses
- application/x-www-form-urlencoded or multipart/form-data?
- Spring Boot – Unable to resolve Whitelabel Error Page
- How to use Python to execute a cURL command?
- Use a JSON array with objects with javascript
- Yahoo Finance All Currencies quote API Documentation
- How to parse data in JSON format?
- What is BSON and exactly how is it different from JSON?
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- Array of JSON Objects
- Chrome sendrequest error: TypeError: Converting circular structure to JSON
- How to convert JSON to XML or XML to JSON?
- How can I set the request header for curl?
- application/x-www-form-urlencoded or multipart/form-data?
- How to use Python to execute a cURL command?
- How to reformat JSON in Notepad++?
- Fetch: POST JSON data
- json.dumps vs flask.jsonify
- Select objects based on value of variable in object using jq
- Uncaught SyntaxError: Unexpected token u in JSON at position 0
- How to define the basic HTTP authentication using cURL correctly?
- What does enctype=’multipart/form-data’ mean?
- How to use the curl command in PowerShell?
- https connection using CURL from command line
- performing HTTP requests with cURL (using PROXY)
- Failed to load PDF document in Chrome
- TypeError: unhashable type: ‘dict’, when dict used as a key for another dict
- uncaught syntaxerror unexpected token U JSON
- How to define the basic HTTP authentication using cURL correctly?
- What is the difference between YAML and JSON?
- Possible reason for NGINX 499 error codes
- How to install JQ on Mac on the command line?
- What does enctype=’multipart/form-data’ mean?
- Unexpected token u in JSON at position 0 (but only sometimes)
- How to read an external local JSON file in JavaScript?
- Representing null in JSON
- “CAUTION: provisional headers are shown” in Chrome debugger
- SyntaxError: Unexpected token o in JSON at position 1