>_ IzzyLab

Hands-on task

This task is step 10 of the course “curl and HTTP APIs”

Follow the redirect

easy~3 min

The path http://localhost/old responds with a redirect (HTTP 302) to another path. By default curl doesn't follow a redirect — make it follow through to the end and save the final body to /root/final.txt.

In the Site tab, click the /old link: the browser follows the redirect on its own and shows the final page. curl only does that when asked.

What you'll practise:
  • curl
  • http
  • redirects
  • 302
  • location

Topic breakdown

Responses with 3xx codes and a Location header are redirects: the server says "what you need is at another address". By default curl doesn't follow such a redirect and returns the empty body of the intermediate response. To get the content of the final page, the client must explicitly be allowed to follow the chain of redirects with the corresponding option (mnemonic — from the word location).

What's checked

  1. redirect followed, final body saved

What it looks like