Giter Site home page Giter Site logo

Comments (2)

UgmaDevelopment avatar UgmaDevelopment commented on July 26, 2024

I ran into this same issue.

When using cURL, I get the same error you did.

However, I was able to run the equivalent request using Postman and it succeeded. Seems like a funkiness with cURL is at play.

from tut-rest.

UgmaDevelopment avatar UgmaDevelopment commented on July 26, 2024

Ooh, I seem to have gotten it!

If you're using Windows it looks like you need to

  • replace the outer single quotes (') with double quotes (") and
  • escape any inner double quotes (") within the JSON
    • to escape, replace all " with \"

Doing so results in the following command:

curl -v -X POST localhost:8080/employees -H "Content-Type: application/json" -d "{\"name\": \"Samwise Gamgee\", \"role\": \"gardener\"}"

then you'll get a response something like:

Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /employees HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 46
>
} [46 bytes data]
* upload completely sent off: 46 out of 46 bytes
< HTTP/1.1 201
< Location: http://localhost:8080/employees/6
< Content-Type: application/hal+json
< Transfer-Encoding: chunked
< Date: Fri, 08 May 2020 06:54:42 GMT
<
{ [221 bytes data]
100   256    0   210  100    46    210     46  0:00:01 --:--:--  0:00:01  4063
* Connection #0 to host localhost left intact
{
    "id": 6,
    "firstName": "Samwise",
    "lastName": "Gamgee",
    "role": "gardener",
    "name": "Samwise Gamgee",
    "_links": {
        "self": {
            "href": "http://localhost:8080/employees/6"
        },
        "employees": {
            "href": "http://localhost:8080/employees"
        }
    }
}

...or just use Postman or something similar. 🤷‍♂️

This is the StackOverflow answer that helped me solve it.

from tut-rest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.