Is there a way to follow redirects with command line cURL?

后端 未结 3 1314
礼貌的吻别
礼貌的吻别 2020-11-29 15:33

I know that in a php script:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

will follow redirects. Is there a way to follow redirects with

3条回答
  •  日久生厌
    2020-11-29 16:06

    As said, to follow redirects you can use the flag -L or --location:

    curl -L http://www.example.com
    

    But, if you want limit the number of redirects, add the parameter --max-redirs

    --max-redirs 
    

    Set maximum number of redirection-followings allowed. If -L, --location is used, this option can be used to prevent curl from following redirections "in absurdum". By default, the limit is set to 50 redirections. Set this option to -1 to make it limitless. If this option is used several times, the last one will be used.

提交回复
热议问题