NekoLopez
NekoLopez

Reputation: 609

How invoke this code in Curl?

I need to turn this code in curl for HTTP REQUEST

POST https://www.mylink.com/dir/comment/itemID

HEADER
Content-Type: application/json
Token-Key: {tokenKey}

BODY
{
 "quantity":"{quantity}"
}

I tried this way:

curl -v --url https://www.mylink.com/dir/comment/itemID -H "Content-Type:application/json" -H "Token-Key:tokenKey" --data "quantity=myquantity"

But it shows me error code 405.

I'd like some help.

Upvotes: 1

Views: 60

Answers (2)

guness
guness

Reputation: 6656

I would suggest using https://requestb.in in order to debug your request. This one just works as you wanted to work:

curl -H "Content-Type:application/json" -H "Token-Key:tokenKey" -d "{\"quantity\": 10101}" https://requestb.in/11zr87w1

However it HTTP 405 states that post is not allowed.


Note: I have no relation with requestb.in, I am just a developer who uses it

Upvotes: 0

Scriptonomy
Scriptonomy

Reputation: 4055

Your data encoding is not JSON, change it like this:

--data "{\"quantity\": myquantity }"

But this is not why you are getting a 405 method not allowed. It's possible you are making a request to an endpoint that does not allow POST.

Upvotes: 1

Related Questions