當我在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'
重新測試,解決問題。
參考資料
- Linux curl get請求參數多個參數被截斷的解決方法:https://blog.csdn.net/top_cod...