how to test curl or wget for a particular link?
- User
how to test curl or wget for a particular link?
- Assistant
how to test curl or wget for a particular link?
To test a URL using curl or wget, you can run simple commands to fetch the content of the link, check its status, and perform other actions. Here are basic usage examples for both tools:
curlFetch the Content:
curl http://example.com
This command will display the contents of the URL in the terminal.
Save the Output to a File:
curl -o output.html http://example.com
This command will save the contents of the URL to a file named output.html.
Check the HTTP Status Code:
curl -I http://example.com
This will display the HTTP headers, including the status code.
Follow Redirects:
curl -L http://example.com
This command will follow any redirects (useful if the initial URL redirects to another URL).
Check the Download Speed:
curl -w "%{speed_download}\n" -o /dev/null -s http://example.com
This will display the download speed of the URL.
wgetFetch the Content:
wget http://example.com
By default, wget will save the content to a file named after the last component of the URL.
Save the Output to a Specific File:
wget -O output.html http://example.com
This command will save the contents of the URL to a file named output.html.
Check the HTTP Status Code:
wget --server-response --spider http://example.com
The --server-response flag will display the HTTP headers, and the --spider flag tells wget to not download the body (just to check the URL).
Follow Redirects:
wget --max-redirect=10 http://example.com
This command will follow redirects up to 10 times.
Download in the Background:
wget -b http://example.com
This will start downloading the file in the background.
curl to Check a URLcurl -I http://example.com
The output will include:
HTTP/1.1 200 OK
Date: Mon, 01 Jan 2023 00:00:00 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 1270
Connection: keep-alive
wget to Check a URLwget --server-response --spider http://example.com
The output will include:
Spider mode enabled. Check if remote file exists.
--2023-01-01 00:00:00-- http://example.com/
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Mon, 01 Jan 2023 00:00:00 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 1270
Connection: keep-alive
Length: 1270 (1.2K) [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
These examples should help you to test whether a link is working correctly and gather additional information about the response from the server.
Not yet included in a published release.