Shares 24

cURL is a command line tool to get or send data using URL syntax. If you are working in the support function, one must be aware of cURL command usage to troubleshoot web applications. cURL is cross-platform utility means you can use on Windows, MAC, and UNIX.

Following are some of the most used syntaxes with an example to help you.

1. Verify if you can connect to URL

If you are working on UNIX system and trying to connect external URL, the first thing you wish to do is to check if you can actually access URL through curl. To do so: –

curl yoururl.com

2. Save URL/URI output to file

If you have to save the URL or URI contents to specific file, you can use following syntax

curl yoururl.com > yoururl.html

ex:

[[email protected]  ]# curl 74.125.68.100 >/tmp/google.html     % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                    Dload  Upload   Total   Spent    Left  Speed   100 17383    0 17383    0     0   119k      0 --:--:-- --:--:-- --:--:--  119k   [[email protected]  ]#

Above example will save all the contents from  74.125.68.100 to /tmp/google.html.

3. Show request and response header

if you are having issues and would like to validate actually you are getting expected request and response header.

curl -v yoururl.com

ex:

[[email protected]  ]# curl -v 74.125.68.100   * About to connect() to 74.125.68.100 port 80 (#0)   *   Trying 74.125.68.100...   * Connected to 74.125.68.100 (74.125.68.100) port 80 (#0)   > GET / HTTP/1.1   > User-Agent: curl/7.29.0   > Host: 74.125.68.100   > Accept: */*   >   < HTTP/1.1 200 OK   < Date: Sun, 18 Jan 2015 06:02:58 GMT   < Expires: -1   < Cache-Control: private, max-age=0   < Content-Type: text/html; charset=ISO-8859-1   < Set-Cookie: NID=67=EZH_o3sPvCSnxzVatz21OHv_vB28KOe93IDzSyJ4gOHOABLItEMLZ2jr7i5inZ7dAnnp0X6vDBLWKgmcMRJnrax_-ZFIAj3LEvKnUYpoDCbcOZ8XnMYN7UDLOg5lA0hg; expires=Mon, 20-Jul-2015 06:02:58 GMT; path=/; domain=.; HttpOnly   < P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."   < Server: gws   < X-XSS-Protection: 1; mode=block   < X-Frame-Options: SAMEORIGIN   < Alternate-Protocol: 80:quic,p=0.02   < Accept-Ranges: none   < Vary: Accept-Encoding   < Transfer-Encoding: chunked   <

4. Download at limit rate

if you are working on optimization and would like to see how much time does it take to download at a particular speed, you can:-

curl –-limit-rate 2000B

ex:

curl –-limit-rate 2000B 74.125.68.100

5. Using proxy to connect

If you are to check if you can access using proxy, you can use following syntax:-

curl --proxy yourproxy:port http://yoururl.com

6. Test URL with injecting header

You can user curl  by injecting header with your data to test or troubleshoot the specific issue. Let’s see following example to request with Content-Type

curl --header 'Content-Type: application/json' http://yoururl.com

By doing above, you are requesting curl to pass Content-Type as application/json in the request header.

7. Add extra header

You can add an extra header in the request by using –header syntax.

curl –-header “X-CustomHeader: GeekFlare” http://yoururl.com

ex:

[[email protected]  ]# curl -v --header "X-CustomHeader: GeekFlare" 74.125.68   * About to connect() to 74.125.68.100 port 80 (#0)   *   Trying 74.125.68.100...   * Connected to 74.125.68.100 (74.125.68.100) port 80 (#0)   > GET / HTTP/1.1   > User-Agent: curl/7.29.0   > Host: 74.125.68.100   > Accept: */*   > X-CustomHeader: GeekFlare   >   < HTTP/1.1 200 OK   < Date: Sun, 18 Jan 2015 08:30:25 GMT   < Expires: -1   < Cache-Control: private, max-age=0   < Content-Type: text/html; charset=ISO-8859-1   < Set-Cookie: NID=67=CkzDX-zTtWA0d9M1QVG4O3Imm9YGteC8-Mm-_EtT3V_sZpXUfTxX2jlxzDFpRlup3QCt9ojikXeyVBWIaNeDA_Ex_em2gm-EZHJkQJSg772kEVpYxQERzDObSZhYSIEq; expires=Mon, 20-Jul-2015 08:30:25 GMT; path=/; domain=.; HttpOnly   < P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."   < Server: gws   < X-XSS-Protection: 1; mode=block   < X-Frame-Options: SAMEORIGIN   < Alternate-Protocol: 80:quic,p=0.02   < Accept-Ranges: none   < Vary: Accept-Encoding   < Transfer-Encoding: chunked

8. Display only response header

If you are doing some troubleshooting and quickly want to check response header, you can use following syntax.

curl --head http://yoururl.com

ex:

[[email protected]  ]# curl -I 74.125.68.100   HTTP/1.1 200 OK   Date: Sun, 18 Jan 2015 08:31:22 GMT   Expires: -1   Cache-Control: private, max-age=0   Content-Type: text/html; charset=ISO-8859-1   Set-Cookie: NID=67=SpnXKTDUhw7QGakIeLxmDSFOA-g7WVFA43Yf3EYAq3NbHygnlhfBKnobwB0TI506IMBXk-ReItXYmDo_9_8sjJ2ufphrbZ3iq7jUoHYbR5_ZrLWislvv94ShyObETgkl; expires=Mon, 20-Jul-2015 08:31:22 GMT; path=/; domain=.; HttpOnly   P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."   Server: gws   X-XSS-Protection: 1; mode=block   X-Frame-Options: SAMEORIGIN   Alternate-Protocol: 80:quic,p=0.02   Transfer-Encoding: chunked   Accept-Ranges: none   Vary: Accept-Encoding     [[email protected]  ]#

9. Connect HTTPS/SSL URL and ignore any SSL certificate error

If you are trying to access https URL and that is having certificate error due to host name mismatch or others, you can ignore them by using the following syntax.

curl --insecure https://yoururl.com

10. Connect using specific protocol (SSL/TLS)

Very handy if you would like to connect URL only on SSL V2/V3 or TLS protocol. You can use following syntax.

To connect using SSV2:

curl --sslv2 https://yoururl.com

To connect using SSLV3:

curl --sslv3 https://yoururl.com

To connect using TLS:

curl --tlsv1 https://yoururl.com

11. Download file from FTP Server

You can use curl to download the file as well by specifying username and password.

curl -u user:password -O ftp://ftpurl/style.css

You can always use “-v” with any syntax to print in verbose mode.

Bonus: You may also use following online tools which help you to execute cURL.

Online CURL – a lightweight tool to fetch the URL online and the possibility to add following options.

--connect-timeout
--cookie
--data
--header
--head
--location
--max-time
--proxy
--request
--user
--url
--user-agent

Sample output:

curl-online

Hurl.it – another wonderful tool where you can execute cURL with authentication, headers, and custom parameters.

cURL command line builder – this one is different. It helps you to build the curl command where you can enter information in nice UI and at the bottom, you will get cURL command.

curl-builder

I hope above cURL command and tools help you in real-time connectivity troubleshooting.

Shares 24

Reader Interactions

Comments

Your email address will not be published. Required fields are marked *