本文翻译自:Is there a way to follow redirects with command line cURL?

I know that in a php script: 我知道在php脚本中:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

will follow redirects. 将遵循重定向。 Is there a way to follow redirects with command line cURL? 有没有办法使用命令行cURL跟踪重定向?


#1楼

参考:https://stackoom.com/question/1FW6s/有没有办法使用命令行cURL跟踪重定向


#2楼

使用位置标头标志:

curl -L <URL>


#3楼

I had a similar problem. 我遇到了类似的问题。 I am posting my solution here because I believe it might help one of the commenters. 我在这里发布我的解决方案,因为我相信它可能会对评论者之一有所帮助。

For me, the obstacle was that the page required a login and then gave me a new URL through javascript. 对我来说,障碍是该页面需要登录,然后通过javascript给我一个新的URL。 Here is what I had to do: 这是我必须做的:

curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword" <URL>

Note that j_username and j_password is the name of the fields for my website's login form. 请注意,j_username和j_password是我网站登录表单的字段名称。 You will have to open the source of the webpage to see what the 'name' of the username field and the 'name' of the password field is in your case. 您必须打开网页的来源,以查看用户名字段的“名称”和密码字段的“名称”是什么。 After that I go an html file with java script in which the new URL was embedded. 之后我去了一个带有java脚本的html文件,其中嵌入了新的URL。 After parsing this out just resubmit with the new URL: 解析完后,只需使用新URL重新提交:

curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword" <NEWURL>


#4楼

As said, to follow redirects you can use the flag -L or --location : 如上所述, 要遵循重定向,您可以使用标志-L--location

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

But, if you want limit the number of redirects , add the parameter --max-redirs 但是, 如果要限制重定向的数量 ,请添加参数--max-redirs

 --max-redirs <num> 

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". 如果使用-L , - --location ,则此选项可用于防止curl跟随“在荒谬中”重定向。 By default, the limit is set to 50 redirections. 默认情况下,限制设置为50次重定向。 Set this option to -1 to make it limitless. 将此选项设置为-1可使其无限制。 If this option is used several times, the last one will be used. 如果多次使用此选项,将使用最后一个选项。

有没有办法使用命令行cURL跟踪重定向?相关推荐

  1. 命令行curl上传文件_命令行基础知识:使用cURL下载文件

    命令行curl上传文件 Client URL, or simple cURL is a library and command-line utility for transferring data b ...

  2. curl 升级 php,将命令行cURL转换为PHP cURL

    我从来没有做过任何卷曲,所以需要一些帮助.我试图从例子中解决这个问题,但无法理解它! 我有一个curl命令,我可以从linux(ubuntu)命令行成功运行,该命令行通过api将文件放入wiki. 我 ...

  3. 命令行CURL教程,可以用来在linux下向web服务器发GET等请求

    CURL? 嗯,说来话长了~~~~ 这东西现在已经是苹果机上内置的命令行工具之一了,可见其魅力之一斑 1) 二话不说,先从这里开始吧! curl http://www.yahoo.com 回车之后,w ...

  4. 命令行linux iso,linux – 有没有办法从命令行更改.iso文件卷id?

    我在 linux下有一个.iso文件,并且一直试图找到一种方法来更改卷ID而无需重新创建.iso文件.大多数创作工具(如mkisofs)都提供了一个用于设置音量(-V)的开关.但是我无法弄清楚如何在预 ...

  5. [命令行] curl查询公网出口IP

    一般 curl ipinfo.iocurl https://ip.cncurl cip.cccurl myip.ipip.netcurl ifconfig.mecurl http://members. ...

  6. 命令行查看公网IP地理位置 使用curl

    查询公网IP地址位置 1,使用curl命令 查看本机公网IP地理位置 2,查询指定公网IP地理位置信息 3,返回公网IP 4,ipinfo.io 1,使用curl命令 查看本机公网IP地理位置 cur ...

  7. Linux鼠标滚轮不是滑动页面而是翻历史命令行

    问题 问题如题,突然之间有台机器的Linux鼠标滚立案变得不是一般的滑动页面,而是翻历史命令行. 很不习惯. 解决办法 在命令行下,输入 vi 进入vim,之后输入:q! 退出,就完成来屏幕模式的交替 ...

  8. Elasticsearch 7.7.0 基本操作-基于 CMD 命令行

    ES7.0命令行操作 #检查ES节点是否正常启动 curl http://localhost:9200 #cat检测集群健康状况 curl http://localhost:9200/_cat/hea ...

  9. CMD命令行高级教程精选合编合集

    目录 第一章 批处理基础 第一节 常用批处理内部命令简介 1.REM 和 :: 2.ECHO 和 @ 3.PAUSE 4.ERRORLEVEL 5.TITLE 6.COLOR 7.mode 配置系统设 ...

最新文章

  1. Trust is the most important thing to the team!
  2. linux下wget的用法
  3. oracle数据库导入txt,oracle数据库导入TXT文件方法介绍
  4. mysql phpmyadmin 安装_phpmyadmin怎么安装
  5. 2021款iPad Pro跑分曝光:远超安卓阵营产品
  6. 有哪些必看的前端 JS 库?
  7. 如何定义一个类对象并用next()的方法使用_python零基础必读--可迭代对象、迭代器与生成器...
  8. 听飞狐聊JavaScript设计模式系列12
  9. excel隐藏行的展现方法
  10. MPEG LA提供一站式ATSC 3.0许可证
  11. 搜狗浏览器收藏夹误删恢复
  12. Spring boot视频播放(解决MP4大文件无法播放),整合ffmpeg,用m3u8切片播放。
  13. 微信任务(投票)分发平台
  14. 出现“性能监视器计数器要求”错误的解决办法
  15. 【MacOS】虚拟机Vmware安装MacOS
  16. UEFI启动和Bios(Legacy)启动的区别
  17. windows CE初次接触(一次升级长安致尚XT高德导航的经历)
  18. python安装http server轻量应用服务器的方法
  19. 从spaceX的火箭回收想到的一些事儿
  20. TL431做比较器该如何理解?

热门文章

  1. 安卓高手之路之 图形系统之 图形框架(1)
  2. BottomNavigationView+ViewPager+Fragment仿微信底部导航栏
  3. Android开发 Butterknife使用方法总结
  4. 第四周项目五-用递归方法求解(输出Fibnacci序列的第20个数)
  5. python断点调试不起作用flask_关于python的flask框架下的调试
  6. C语言函数集(二十一)
  7. MapReduce—第一个WordCount程序
  8. Zxing二维码开源项目
  9. swift_036(Swift之第三方库SwiftyJSON篇)
  10. vue插槽样式_vue 插槽简介及使用示例