8

I use simple shell script to test some http server that process POST requests. Usually it looks like:

echo "param1=value1&param2=value2" | POST localhost/service

But now I want to pass also some json in POST body and that's where I missing point completely.

man POST and google did't help much also.

Seems it must be either very simple or completely impossible.

Thanks for help.

mtmk
  • 6,176
  • 27
  • 32
Vlad Fedin
  • 498
  • 5
  • 8

2 Answers2

5

Either I'm missing something, or you should do

$ echo -n '{"json":"data"}' | POST -c "application/json" 'http://localhost/service?param1=value1&param2=value2'

If you need to put those parameters not as GET, but as POST as well, then look up multipart form data.

Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
  • You probably mean `echo -n '{"json":"data"}' | POST -c "application/json" localhost/service` That's good, but still leave me with problem how to pass request parameters `"param1=value1&param2=value2"` – Vlad Fedin Aug 10 '11 at 08:13
  • Yeah, I got it. The only chance to pass both body and params to http request is to use GET parameters. That's my lack of http requests understanding, thanks for help. Can't upvote yet, lack reputation. – Vlad Fedin Aug 10 '11 at 17:44
1

You probably need to pass content type using -c:

POST -c application/json
mtmk
  • 6,176
  • 27
  • 32
  • Wouldn't you be so kind to specify exact command line look? `echo "param1=value1&param2=value2" | POST -c application/json "some body content here" localhost/service` didn't work. – Vlad Fedin Aug 09 '11 at 22:44