Curl Post Data From Terminal with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/curl-post-data-terminal-examples/
PINTEREST
PINTEREST
INSTAGRAM

curl is useful tool used to create HTTP, HTTPS, FTP, … and similar protocol request from command line. This provides us the ability to simulate web browser behavior or similar application logic without a GUI. In this tutorial we will look different use cases for curl POST and JSON. For more information about curl can be get from following tutorial.

Linux curl Command Tutorial With Examples

Simple POST Example

We will start with simple POST example. We will provide some field in the POST with the --data option. In this example we will provide username=ismail&password=poftut as POST data. Use double escapes to delimit data we wan to post.

Read POST Data From File

What if we have more data that is not suitable to write one by one of speficy from command line. Or we may need to provide data as file. We can use the same --data option but we have to provide the file name with @ prefix. In this example we will provide file named mydata.txt as POST data.

Set Content Type

Up to now we have used the default Content type. Some times we may need to specify the content type explicitly. We will use -H option which is used to specify HTTP header where we will provide Content-Type header. In this example we will set PDF ad content type.

Post JSON Data

JSON is popular data format used recently in high volumes. JSON is easily readable structured and light data format. We can send POST Request to the server by providing JSON Data. We just need provide the Content-Type as application/json and put JSON data accordingly. In this example we will send count JSON data.

LEARN MORE  Wget Command Tutorial With Examples For Linux

Post JSON Multiple  Key=Value Like Username and Password

One of the most popular use case for JSON curl is sending username and password data to the server. We have to specify both key and values accordingly like below.

Read JSON POST Data From File

We have read normal POST data from a file. But we can also read JSON POST data from file where we just need to specify file name like below.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/curl-post-data-terminal-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)