本文介绍了卷曲302重定向不工作(命令行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览器中,导航到该URL发起302(临时移动)请求,进而下载文件。

In the browser, navigating to this URL initiates a 302 (moved temporarily) request which in turn downloads a file.

<一个href=\"http://www.targetsite.com/target.php/?event=download&task_id=123\">http://www.targetsite.com/target.php/?event=download&task_id=123

当我查看的内容是通过网络浏览器工具,我看到重定向将会是下载后立即取消本身就是一个动态生成的路径实际发生的情况。换句话说,即使我知道完整的路径,我不会有时间去手动调用它。

When I view what is actually happening via Chrome network tools I see that the redirect is going to a dynamically generated path that cancels itself immediately after download. In other words, even if I know that full path I will not have time to manually call it.

那么,如何在使用命令行,我可以模仿浏览器的行为?

So, how in using the command line can I mimic the browser actions?

我试过

卷曲--cookies斌/ cookie.txt的-O -L<一个href=\"http://www.targetsite.com/target.php/?event=download&task_id=123\">http://www.targetsite.com/target.php/?event=download&task_id=123\" --com pressed

不过这只是返回的乱码。这样做的目的是为了编程下载这个文件,而无需浏览到该网站。不幸的是,我不能在这里分享网站,因为它是一个登录落后。

but this just returns gibberish. The goal of this is to programmatically download this file without having to navigate to the site. Unfortunately I cannot share the site here as it is behind a log-in.

推荐答案

您需要提供 -L - 位置为了使卷曲遵循HTTP重定向的选项。

You need to supply the -L or --location option in order to enable curl to follow HTTP redirects.

男人卷曲引用:

   -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.

这篇关于卷曲302重定向不工作(命令行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:51