Search code examples
linuxshellunixgnulynx

How to post JSON data using lynx command line?


I am able to post JSON using curl like below and able to get JSON output

curl -X POST -H Content-Type:application/json -d '{"xyz":"abc"} http://mymachine.com/test.jsp

output -

{"sucess":"pqr"}

But in my stage box I dont have curl so trying to do same using lynx

I tried below

echo -e '{"xyz":"abc"}\n---\n' | lynx -head 'Content-Type: application/json' -post_data http://mymachine.com/test.jsp

above command is not working, I am getting output {"error":"pqr"} which will come only when test service didnt receive any output.

Can please let me know what might be the issue here?


Solution

  • If you look at the lynx man page, you'll see that -head is for sending HEAD requests, it doesn't set a http header for the request.

    There is no option listed in the man page that would set a request header, the content type for POST requests will always be application/x-www-form-urlencoded.

    You'll probably have to find another tool to do the job, try to look if something useful is installed (wget, nc, ncat, bash, ...).

    If you tell me what's available, I can probably give you a concrete example.