Curl

From Omnia
Revision as of 03:16, 14 July 2026 by Kenneth (talk | contribs) (→‎keywords)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Return status code only

curl -s -o /dev/null -w "%{http_code}" google.com
curl -s -o /dev/null -i -w "%{http_code}" google.com
curl -s -o /dev/null -I -w "%{http_code}" google.com
curl -s -o /dev/null -I -w "%{http_code}\n" google.com

ref: [1]

Return fail status code

curl --fail http://some-url.com
echo $?
-f, --fail (HTTP) Fail silently (no output at all) on server errors

Connect to server by ip and pass hostname

Option #1:

  • Add to C:\windows\system32\drivers\etc\hosts

Option #2:

curl --resolve example.com:443:192.168.1.100 https://example.com/hello
"This command will send a request to the IP address 192.168.1.100, but it will include example.com in the Host header, which is crucial for virtual hosting and TLS/SSL certificate validation."
curl --resolve <host:port:address> <URL>
 host: The hostname you want to use in the request.
 port: The port number for the connection.
 address: The IP address you want to connect to.
 URL: The URL you want to request, using the specified hostname.

Option #3: (will convert connection of example.com to altexample.com) [2]

curl --connect-to example.com:80:altexample.com:80 http://example.com
# shorthand:
curl --connect-to ::altexample.com http://example.com
curl --connect-to ::altexample.com:8080 http://example.com

Option #4: (this does not seem to work??)

curl [IP] -k -H 'Host: example.com'

Ignore SSL Revocation Check

C:\> curl -v -I https://github.com/
* Host github.com:443 was resolved.
* IPv6: (none)
* IPv4: 140.82.116.4
*   Trying 140.82.116.4:443...
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* schannel: next InitializeSecurityContext failed: CRYPT_E_NO_REVOCATION_CHECK (0x80092012) - The revocation function was unable to check revocation for the certificate.
* closing connection #0
curl: (35) schannel: next InitializeSecurityContext failed: CRYPT_E_NO_REVOCATION_CHECK (0x80092012) - The revocation function was unable to check revocation for the certificate.

Option #1 - brute force (Insecure):

curl ---k -v -I https://github.com/

Option #2 - no revoke check (more secure):

curl --ssl-no-revoke -v -I https://github.com/

Option #3 - best effort revoke check (best attempt secure):

curl --ssl-revoke-best-effort -v -I https://github.com/

Post JSON

curl -X POST -H "Content-Type: application/json" -d @FILENAME DESTINATION
curl -X POST -H "Content-Type: application/json" -d @../data/cats.json http://localhost:8080/mSfvMwNAfj

You can try to do it all in the terminal, generally a bad idea:

curl -X POST -H "Content-Type: application/json" -d '{"type":"Feature","properties":{"COUNTY":"M","PRECINCT":4505.0,"AREA":24330472.48801},"geometry":{"type":"Polygon","coordinates":[[[-122.579029970781065,45.53373981165327],[-122.579036751674209,45.533742065313575],[-122.579532751335037,45.533906068395808],[-122.579961749295705,45.534067060396104],[-122.580146749064056,45.534114065074704],[-122.581902757566823,45.534772060883959],[-122.582770766094569,45.535128058282019],[-122.583461773870638,45.535383050711246],[-122.584275765662781,45.535596050402262],[-122.584926770675438,45.535732043153857],[-122.585534768605342,45.535823041352423],[-122.586393777046183,45.535863042628513],[-122.586845771939593,45.535841037753478],[-122.587166778711079,45.535850042847976],[-122.587593783117342,45.535829037919441],[-122.587900782381638,45.535804036638346],[-122.588290773918729,45.535750036812139],[-122.588704782064923,45.535671034778389],[-122.589196776268082,45.535561035548149],[-122.589239647326053,45.535550318867173],[-122.589320708749753,45.536124484404517],[-122.589304695035338,45.537268231315537],[-122.59947923271595,45.53740953002616],[-122.599372142997979,45.537656509885132],[-122.601520781310597,45.537617244011571],[-122.601391421360532,45.543541079913162],[-122.578671442407,45.552336859399695],[-122.578672106607101,45.55230042862145],[-122.578693794893084,45.551092987187559],[-122.578713188347777,45.549969468845575],[-122.579029970781065,45.53373981165327]]]}}' http://localhost:8080/mSfvMwNAfj

[3]

keywords