curl 302重定向不起作用(命令行)

 闻人特荷焦黄01965 发布于 2023-02-06 18:35

在浏览器中,导航到此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--location选项才能启用curlHTTP重定向.

    引用自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.
    

    2023-02-06 18:36 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有