Recently I used curl command a lot in several Continuous Integration projects. I wrote this post to summarize a few commonly-used options.
This option enables silent mode, in which progress bar and error messages will not shown
This option enables curl to show error message, when combined with ‘-s’ option.
When curl receives a ‘3xx’ response from a server, curl will follow the location in the response to resend the request
This option enables curl to upload the specified local file to the remote url
This option enables curl to include additional http headers when sending http requests. One of the commonly-used headers is ‘Authorization’ header. This header can contain ‘Bearer’ or ‘Basic’ token to authenticate with the remote server. For example, using the generated token in JFrog Artifactory user profile as Bearer token in ‘Authorization’ header to uploading files to JFrog repository is a very common use case.
-b <filename|key-value pairs>
This option enables curl to include cookies in http request. Two forms of arguments can be provided for this option. I will only introduce one format, which has form ‘param=value; param=value’. I used this form when I want to download repository archives from Gitlab instance. After I login to Gitlab Web GUI, the web browser will store session cookie received from the server. This session cookie can be shown when using developer mode in browser. Then the cookie ‘_gitlab_session=xxxxxx’ can be included in http request to download repository archives. The below link explains the session cookie in Gitlab
This option is also very useful from my point of view. However, it only available since version 7.76.0. This option enables curl to fail with error when the server delivers a response with http code 400 or larger.
This option enables curl to fail silently on server errors.
This option allows to specify username and password in the http request