[英]check server response with curl -D
據我在man curl頁面上看到的那樣,-D選項應該為我提供服務器對我發送的請求的響應。 當我嘗試讀取所需的文件時,該文件存儲在我連接的服務器上,我可以正確地讀取它:
curl -uUSERNAME:PASS SERVER-NAME/path-to-file > my_output
這是成功的,所以我可以正確使用我使用的憑據。 現在,我想創建一個預讀驗證步驟,該步驟首先讀取對我的訪問嘗試的響應,如果收到200 OK,則繼續請求文件...所以我使用
curl -D -uUSERNAME:PASS SERVER-NAME > my_output
現在我收到401響應,但我沒有得到:
<title>401 Authorization Required</title>
有什么建議嗎?
嘗試這樣做:
intvar=$(curl -s -w %{http_code} http://SERVER-NAME/path-to-file -o /dev/null)
case $intvar in
4*|5*)
echo >&2 "Fatal: HTTP $intvar code spotted."
exit 1
;;
2*|3*)
echo "HTTP $intvar code spotted."
# 2nd curl command
;;
esac
見:
man curl | less +/^' *-w'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.