in Technology by
How can we POST JSON data with cURL?

1 Answer

0 votes
by
You need to set your content-type to application/json. But -d 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: -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 questions

0 votes
    This is a cURL function that can send or retrieve data. It should work with any PHP app that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    URL is http://*.*.*.*/100/?id=1&version=1 params is {"cityId": "110000", "query": {" ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    How can we write JSON data to a file?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I am working on my first Android Application. What I am trying to do is a POST request to a REST ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Which of the following is correct? A.We can use json data directly in axios B.we can use json data directly ... only we can use axios Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    How can we pretty-print JSON in a shell script?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    Can We use comments inside a JSON file? If so, how?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    Why can't we Python parse this JSON data?...
asked Jan 11, 2021 by JackTerrance
0 votes
    Can we use JSON instead of YAML while developing docker-compose file in Docker?...
asked Jun 21, 2021 in Technology by JackTerrance
0 votes
    first of all,i am fairly new with spring mvc so .. how springmvc find the right class to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have a page with a form that posts to salesforce.com's webto Lead service. I am trying to make an ... receiving website can see? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a page with a form that posts to salesforce.com's webto Lead service. I am trying to make an ... receiving website can see? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    We need an active internet connection to publish the post.(T/F) True False Select the correct answer from above options...
asked Nov 29, 2021 in Education by JackTerrance
0 votes
    object looks like as below { "id":1, "image":"path/to/image", "employee_data":, } again ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    object looks like as below { "id":1, "image":"path/to/image", "employee_data":, } again ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...