Hot answers tagged

106 votes

Can I make cURL fail with an exitCode different than 0 if the HTTP status code is not 200?

Use --fail-with-body. This will cause curl to exit with status code 22 when response code is >=400. Note though that this flag is brand new (as of 2021/02/15), and was added in version 7.76.0, ...
phemmer's user avatar
  • 2,095
104 votes
Accepted

Specifying minor TLS version when using curl

Curl has options to control the TLS version used. At the date of the last revision to this answer, if you want to specify that TLS 1.2 is used but not 1.1 or 1.3 etc, you need something like curl --...
RedGrittyBrick's user avatar
100 votes

Can I make cURL fail with an exitCode different than 0 if the HTTP status code is not 200?

I was able to do it using a combination of flags: curl --silent --show-error --fail URL --silent hides the progress and error --show-error shows the error message hidden by --silent --fail returns an ...
Ricardo Souza's user avatar
84 votes

PowerShell equivalent of curl

As of Powershell 5.0, if not before, curl is an alias for Invoke-WebRequest. PS> Get-Alias -Definition Invoke-WebRequest | Format-Table -AutoSize CommandType Name Version ...
John Bentley's user avatar
81 votes
Accepted

Can I make cURL fail with an exitCode different than 0 if the HTTP status code is not 200?

Most of the answers provided so far will not print the HTTP response body in case an HTTP request fails. If you would like to print the response body as well, even if the exit code is non-zero due to ...
jtompl's user avatar
  • 942
53 votes

Getting curl to output HTTP status code?

Status code ONLY [0]$ curl -LI http://www.example.org -o /dev/null -w '%{http_code}\n' -s [0]$ 200 All credit to this GIST
mahatmanich's user avatar
51 votes

How do you display POST data with cURL?

Or you could test with https://httpbin.org/ $ curl https://httpbin.org/post -d "firstname=john&lastname=doe" { "args": {}, "data": "", "files": {}, "form": { "firstname": "john", ...
Christophe Morio's user avatar
50 votes
Accepted

How to POST file contents using cURL?

According to the last section of -d in man curl: If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. ...
user556625's user avatar
  • 4,180
47 votes

How do I make a POST request using curl?

If you are lazy, you can get google-chrome or firefox to do all the work for you. Right-click the form you want to submit and select Inspect (or Inspect Element for Firefox). This will open the ...
ccpizza's user avatar
  • 7,558
44 votes
Accepted

'http" not supported or disabled in libcurl

Ensure you are supplying curl with double quotes ("), not single quotes (') Curl in Windows is know to not like single quotes as per (for example) this thread: D:\nr\platform_installer_win32>...
bertieb's user avatar
  • 7,384
39 votes

How to POST file contents using cURL?

As mentioned in this related question if you want the file uploaded without any changes (curl defaults to stripping carriage-return/line-feed characters) then you may want to use the --data-binary ...
Pierz's user avatar
  • 1,929
35 votes
Accepted

How to curl case-insensitive

It's not curl that decides case-insensitivity at all – link "checking" is the server's decision. (In other words, HTTP clients do not have the opportunity to see the list of all possible ...
u1686_grawity's user avatar
31 votes
Accepted

curl http_code of 000

The response 000 indicates that cURL failed to execute for some reason. In such a case, you should test for cURL exit code rather than making assumptions. See the "Exit Codes" section of the curl ...
Mikkel's user avatar
  • 825
30 votes

How do you display POST data with cURL?

Would like to add netcat alternative #!/bin/bash nc -l 8080 & curl "http://localhost:8080" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ --...
Gert Cuykens's user avatar
25 votes

How to make a Curl POST call in Windows?

Another option is to mask doublequotes with backslash like this: curl -i -X POST -H "Content-Type:application/json" -d "{\"firstName\": \"Frodo\", \"lastName\" : \"Baggins\" }" http://localhost:8080/...
lospejos's user avatar
  • 351
25 votes

How to POST file contents using cURL?

To be explicitly clear, the accepted answer suggests: curl -d "data=@path/to/my-file.txt" http://example.com/ The manual reference is here. Also see this SE answer and this one also for ...
Mowzer's user avatar
  • 2,209
24 votes

How do you display POST data with cURL?

--trace - works with curl 7.58 and shows you the POST body: $ curl --trace - -d 'foo=bar' http://example.org == Info: Rebuilt URL to: http://example.org/ == Info: Trying 2606:2800:220:1:248:1893:...
cweiske's user avatar
  • 1,897
24 votes
Accepted

How to send POST with body, headers, and HTTP params using cURL?

Not enough reputation to comment so leave this as an answer hoping it help. curl -L -v --post301 --post302 -i -X PUT -T "${aclfile}" \ -H "Date: ${dateValue}" \ -H "Content-Type: ${contentType}" ...
Tiina's user avatar
  • 3,052
23 votes

Windows 10 WSL cURL can't access localhost with error (Failed to connect to localhost port 80: Connection refused)

Updated 2023-10-31 Microsoft is fixing this! The following issues are being resolved with a new feature that's available on preview but appears might roll out to regular update paths in the near ...
bsplosion's user avatar
  • 339
21 votes

Getting curl to output HTTP status code?

This is a painful curl --fail limitation. From man curl : -f, --fail (HTTP) Fail silently (no output at all) on server errors But there is no way to get both the non-zero return code AND ...
Lucas Cimon's user avatar
17 votes

How to curl case-insensitive

Case sensitivity for the part after the domain names is up to the server. To fully emulate case-insensitivity of the server, curl would have to try up to all possible combinations (…LiNUx…, …linUX…) ...
Kamil Maciorowski's user avatar
16 votes
Accepted

Get response body and show HTTP code by curl

It looks like the content of the response is a single line. You could use two read calls to read two lines: curl -s -w "\n%{http_code}" 'https://swapi.dev/api/people/1?format=json' | { ...
janos's user avatar
  • 3,337
15 votes

Getting curl to output HTTP status code?

For a POST request, the following worked: curl -w 'RESP_CODE:%{response_code}' -s -X POST --data '{"asda":"asd"}' http://example.com --header "Content-Type:application/json"|grep -o 'RESP_CODE:[1-4][...
zafar142003's user avatar
15 votes

Specifying minor TLS version when using curl

Curl's behavior has changed! For versions prior to 7.54.0, RedGrittyBrick's answer remains correct. For version of curl after 7.54.0 the options --tlsv1.0, --tlsv1.1 and --tlsv1.2 set the minimum ...
nelsonda's user avatar
  • 253
14 votes
Accepted

SSL cert does not work with IP address for SAN

You're using the wrong SAN type – only actual domain names are allowed in "DNS" type SANs; for IP addresses there is the "iPAddress" type ([7] OCTET STRING). For OpenSSL you can use: ...
u1686_grawity's user avatar
14 votes
Accepted

How do I send a digest auth request using curl?

You don't have to specify all those values anywhere. The only thing you do have to is username/password pair. CURL takes care of computing the client response for you. This is exactly what "...
mina nageh's user avatar
13 votes

Can I make cURL fail with an exitCode different than 0 if the HTTP status code is not 200?

Yes there is a way to do it but is far from obvious as it involves 3 curl options: curl -s --fail --show-error https://httpbin.org/status/200 > /dev/null curl -s --fail --show-error https://...
sorin's user avatar
  • 11.7k
13 votes

Can I make cURL fail with an exitCode different than 0 if the HTTP status code is not 200?

I ended up with this based on Dennis's answer, a quick one-liner that fails for non-200 status codes while retaining the output (to stderr): [ $(curl ... -o /dev/stderr -w "%{http_code}") -...
shesek's user avatar
  • 231
13 votes
Accepted

git on Debian 10 backports throws fatal: unable to access 'https://github.com/user/repo.git': Failed sending HTTP2 data

In other computer with the same system, but with git working normally, I compared the packages not upgraded. Downgrade libcurl3-gnutls to 7.64.0-4+deb10u2 and the problem is solved.
Renato B. Santiago's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible