linux-curl请求时参数被截断

8次阅读

共计 517 个字符,预计需要花费 2 分钟才能阅读完成。

当我在 curl 一个 url 时,发现在后端 PHP 环境使用 xdebug 时,只能捕获第一个参数:

curl test.baidu.com/oss/index.php?r=info/data/query&username=xxx&password=xxx
# 在后端 url 被截断,只能捕获到第一个参数
$_GET: array(1) r: "info/data/query"

这导致了我的认证失败,无法获取正确的数据。

其实这里的原因是在 shell 命令中& 符号有特殊的含义,而并不只是 url 参数的连接符。因此,我们有两种解决方法:

# 方法一:转义,加上 \ 符
curl test.baidu.com/oss/index.php?r=info/data/query\&username=xxx\&password=xxx
# 方法二:包装,在 url 外加上引号,用字符串处理
curl 'test.baidu.com/oss/index.php?r=info/data/query&username=xxx&password=xxx'

重新测试,解决问题。

参考资料

  1. Linux curl get 请求参数多个参数被截断的解决方法:https://blog.csdn.net/top_cod…
正文完
 0