0

If I issue a curl command to a REST api then I get the response below.

curl -i http://10.4.0.22:8088/api/clients/TEST_1/8194/1/1

Response:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 51
Server: Jetty(9.1.z-SNAPSHOT)

{"status":"CONTENT","content":{"id":1,"value":"0"}}

My understanding that this is equivalent to a http GET request.

What I'm trying to do is update the value field and change the value to 1.

I think this requires a POST request using the -d flag.

My question is how do I know what format the data should be in the curl command?

I tried

curl -d "{"status":"CONTENT","content":{"id":1,"value":"1"}}" http://10.4.0.22:8088/api/clients/EST_1/8194/1/1

but I get this response.

{"status":"METHOD_NOT_ALLOWED"}

I think the way that I am specifying the json after te -d flag is incorrect?

artic sol
  • 349
  • 6
  • 18

1 Answers1

0

The response METHOD_NOT_ALLOWED means the server doesn't allow POST method.

You can add a -v to get a verbose output of the response. Sometimes the server responds back in the message as to what HTTP Methods (or Verbs) it allows.

I tried your parameters on my application endpoint and it worked. see below

curl -d "{"status":"CONTENT","content":{"id":1,"value":"1"}}" http://sitename.azurewebsites.net/index.php -v
* Adding handle: conn: 0x2c257d0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x2c257d0) send_pipe: 1, recv_pipe: 0
* About to connect() to sitename.azurewebsites.net port 80 (#0)
*   Trying 104.211.224.252...
* Connected to sitename.azurewebsites.net (104.211.224.252) port 80 (#0)
> POST /index.php HTTP/1.1
> User-Agent: curl/7.33.0
> Host: sitename.azurewebsites.net
> Accept: */*
> Content-Length: 39
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 39 out of 39 bytes
< HTTP/1.1 200 OK
< Content-Length: 0
< Content-Type: text/html
< X-Powered-By: PHP/5.4.45
< Date: Fri, 04 Aug 2017 14:24:08 GMT

You can also try to specify the Content-Type header in your request and set it to corresponding Mime value.

For CURL, you can use the -H with the value set to "Content-Type: application/json"

Have you seen this thread: How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?

Kaushal Kumar Panday
  • 2,329
  • 13
  • 22