User Tools

Site Tools



cURL is a program for making HTTP request, f. e. accessing a web site or calling a web service.

Basic Auth

In Basic Auth the username and password Base64 encoded and added to the HTTP headers. cURL can do this easily with an option.

curl --user my_user:my_pass http://localhost/my/service

Response Format

When using web services one can add a request for a specific format for the response using HTTP headers.

curl http://localhost/my/service -H "Accept: application/json"

Passing Form Parameter

curl -d "name=value&another=value" http://localhost/my/service

Passing Query Parameter

Query parameter are passed in the url by adding key/value pairs after the ? sign in the url. Example:

curl http://localhost/resource?q=query_expression&start=0&rows=0

If this url is used with curl than the parameters start and rows are being dropped and the curl process is executed in the background. Why? Because the first & tells the shell to execute the command in the background. The shell won't recognize it as part of the url.

Solution: Use double quotes.

curl "http://localhost/resource?q=query_expression&start=0&rows=0"

Passing Data from File

Instead of passing the post data from the command line it can also be read from a file:

curl http://localhost/resource -X POST -d @data.json -H "Content-Type: application/json"
curl.txt · Last modified: 2017/10/12 11:21 by mihael