简体   繁体   English

使用curl -D检查服务器响应

[英]check server response with curl -D

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. 据我在man curl页面上看到的那样,-D选项应该为我提供服务器对我发送的请求的响应。 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 现在,我想创建一个预读验证步骤,该步骤首先读取对我的访问尝试的响应,如果收到200 OK,则继续请求文件...所以我使用

curl -D -uUSERNAME:PASS SERVER-NAME > my_output

Now i get a 401 response, i dont get it: 现在我收到401响应,但我没有得到:

<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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM