As far as i can see from the man curl page, the -D option should provide me with the server response to the request i'm sending. When i try to read the file i need, stored on the server i'm connecting to, i can read it properly:
curl -uUSERNAME:PASS SERVER-NAME/path-to-file > my_output
This is successful, so i can acces properly with the credentials i use. Now i would like to create a pre-reading validation step, that first reads the response to my access attempt, if a 200 OK is received, go ahead with requesting the file... So i use
curl -D -uUSERNAME:PASS SERVER-NAME > my_output
Now i get a 401 response, i dont get it:
<title>401 Authorization Required</title>
Any advice?
Try doing this :
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
See :
man curl | less +/^' *-w'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.