Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl command for issuing a POST request

Tags:

http

curl

I am in my Terminal and I want to send a POST request to a given URL. I have tested this with a REST client so I know that the parameters work.

So lets say I want to POST the following parameters:

  • username=tony
  • password=secret

To my URL: https://exmaple.com/login/

I tried the following curl command in my Terminal (I am using OSX Lion)

curl --data "username=tony&password=secret" http://exmaple.com/login/ 

I get an 500 Server Error back from the server so I am now thinking of something that could be different between the REST Client and the curl command.

Thanks for your help

Update: I am using a https service. Do I have to adjust my curl command to account for this?

like image 988
Besi Avatar asked Nov 15 '11 23:11

Besi


People also ask

How do you send a POST request on curl?

When the -F option is used, curl sends the data using the multipart/form-data Content-Type. Another way to make a POST request is to use the -d option. This causes curl to send the data using the application/x-www-form-urlencoded Content-Type.

What is curl POST command?

Curl is a command-line utility that allows users to create network requests. Curl is accessible on Windows, Linux, and Mac, making it the go-to choice for developers across all platforms. We can make POST requests with varying levels of detail.

Does curl do get or POST?

"By default you use curl without explicitly saying which request method to use. If you just pass in a HTTP URL like curl example.com it will use GET. If you use -d or -F curl will use POST, -I will cause a HEAD and -T will make it a PUT." Everything you need to know.


1 Answers

Try this

curl -F username=tony -F password=secret http://exmaple.com/login/ 

-F (reference) should probably do the same as --data? Possible the problem is in the webapp.

Maybe the app you are hitting uses basic auth for authentication? Try this one:

curl --user name:password http://exmaple.com/login/ 
like image 52
russau Avatar answered Sep 30 '22 19:09

russau