curl 302 redirect не работает (командная строка)

в браузере переход к этому URL инициирует 302 (временно перемещенный) запрос, который, в свою очередь, загружает файл.

http://www.targetsite.com/target.php/?event=download&task_id=123

когда я смотрю, что на самом деле происходит с помощью сетевых инструментов Chrome, я вижу, что перенаправление происходит на динамически генерируемый путь, который отменяется сразу после загрузки. Другими словами, даже если я знаю, что полный путь я не буду успейте вручную вызвать его.

Итак, как с помощью командной строки я могу имитировать действия браузера?

пробовал

curl --cookies bin/cookies.txt-O-L"http://www.targetsite.com/target.php/?event=download&task_id=123 " -- сжатый

но это просто возвращает абракадабру. Целью этого является программная загрузка этого файла без необходимости перехода на сайт. К сожалению я не могу поделиться сайтом вот как это бывает за логином.

1 ответов


вам нужно поставить -L или для того чтобы curl следовать перенаправлениям HTTP.

цитирую man curl:

   -L, --location
          (HTTP/HTTPS)  If  the server reports that the requested page has
          moved to a different location (indicated with a Location: header
          and  a  3XX  response code), this option will make curl redo the
          request on the new place. If used together with -i, --include or
          -I, --head, headers from all requested pages will be shown. When
          authentication is used, curl only sends its credentials  to  the
          initial  host.  If a redirect takes curl to a different host, it
          won't be able to intercept the user+password. See  also  --loca‐
          tion-trusted  on how to change this. You can limit the amount of
          redirects to follow by using the --max-redirs option.

          When curl follows a redirect and the request is not a plain  GET
          (for example POST or PUT), it will do the following request with
          a GET if the HTTP response was 301, 302, or 303. If the response
          code  was  any  other  3xx code, curl will re-send the following
          request using the same unmodified method.