linux curl請求時參數被截斷

當我在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...
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章