Thursday, February 16, 2017

Use correct header with CURL

Upon submitting a request to my service like

CURL -X POST http://localhost:8600/a/b/c -d '{"assignmentId[]":[12345]}'

I got this error:

"A servlet request, to the URI http://localhost:8600/a/b/c, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected."

Resolved with this answer from http://stackoverflow.com/a/33636404/187423 (thanks Arnold B.).

When I changed my request to

CURL -X POST http://localhost:8600/a/b/c -H "Content-Type: application/json" -d '{"assignmentId[]":[12345]}'

(adding the header) the service was able to parse the request and handle it normally.

HTH,
kewpiedoll99

1 comment:

Barclay said...

Also you might need to format the data passed like this:

$ curl -X POST -d 'barcode=12345678&locationString=xx-xx-013-x&status=MISRACKED&createdAt=2017-07-24T12:45:00' localhost:8080/cycleScan/1/anomaly


See this SO answer: https://stackoverflow.com/a/26968995/187423