zoukankan      html  css  js  c++  java
  • 常用HTTP状态码和CURL 000问题

      最近在测试CDN服务质量问题,测试过程中返回了一些不同的状态码,当然有一些常用的,也有一些不常用的。最奇葩的是在使用curl命令的时候出现000状态码,问了很多同事,对这个000的反应跟新事物是的。

    一、生产环境常见的HTTP CODE

    生产环境常见的HTTP状态码列表(List of HTTP status codes)为:

    2XX成功:
    200 - OK,服务器成功返回网页
      - Standard response for successful HTTP requests.

    3XX重定向:
    301 - Moved Permanently(永久跳转),请求的网页已永久跳转到新位置。
      - This and all future requests should be directed to the given.
    302 - Moved Temporarily(临时跳转),请求的网页已临时跳转到新位置。

    4XX客户端错误:
    403 - Forbidden(禁止访问),服务器拒绝请求
      - forbidden request (matches a deny filter) => HTTP 403
      - The request was a legal request, but the server is refusing to respond to it.
    404 - Not Found,服务器找不到请求的页面。
      - The requested resource could not be found but may be available again in the future.

    5XX服务器错误:
    500 - Internal Server Error(内部服务器错误)
      - internal error in haproxy => HTTP 500
      - A generic error message, given when no more specific message is suitable.
    502 - Bad Gateway(坏的网关),一般是网关服务器请求后端服务时,后端服务没有按照http协议正确返回结果。
      - the server returned an invalid or incomplete response => HTTP 502
      - The server was acting as a gateway or proxy and received an invalid response from the upstream server.
    503 - Service Unavailable(服务当前不可用),可能因为超载或停机维护。
      - no server was available to handle the request => HTTP 503
      - The server is currently unavailable (because it is overloaded or down for maintenance).
    504 - Gateway Timeout(网关超时),一般是网关服务器请求后端服务时,后端服务没有在特定的时间内完成服务。
      - the server failed to reply in time => HTTP 504
      - The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.

    二、curl奇怪的返回值000。

    经过测试发现在curl的时候出现000的情况有如下几种:

    1.Failed DNS resolution (6)

    $ curl -w "%{http_code} " http://example.invalid/ ; echo "Exit code: $?"
    000
    curl: (6) Could not resolve host: example.invalid
    Exit code: 6

    2.Connection refused (7)

    $ curl -w "%{http_code} " http://localhost:81/ ; echo "Exit code: $?"
    000
    curl: (7) Failed to connect to localhost port 81: Connection refused
    Exit code: 7

    Connection timed out (28)

    $ curl -w "%{http_code} " -m 5 http://10.255.255.1/ ; echo "Exit code: $?"
    000
    curl: (28) Connection timed out after 5001 milliseconds
    Exit code: 28

    Server actually returns 000 for some reason (0)

    开启一个监听端口:

    nc -l -p 65535 & <<EOF

    HTTP/1.1 000 Fake Status Code

    Content-Length: 0

    Connection: close

    EOF

    客户端请求:

    $ curl -w "%{http_code} " http://localhost:65535/ ; echo "Exit code: $?"
    000
    Exit code: 0

    *注释:一般情况下遇到000,默认考虑为200,正常。

    在测试过程中打印了000时的错误信息,错误为:Connection timed out。使用curl时,参数:-sS ,然后将curl的错误 2>> /tmp/err.log。

    参考文章:
    wikipedia:https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

    http://superuser.com/questions/501690/curl-http-code-of-000

  • 相关阅读:
    jquery效果,多个div,点击任何一个div,那么这个div会切换文字,变换背景颜色,再次点击其他的div ,这个div会发生刚才的变化,之前点击的div的颜色会变回来
    用js动态的改变img标签里面的src属性实现图片的循环切换
    清除浮动
    清除浮动clearfix
    转移符 个人工作中使用记录一下
    12.Django数据库操作(执行原生SQL)
    11.Django数据库操作(查)
    10.Django数据库操作(增删改)
    9.Django里的数据同步migrations命令
    8.Django模型类例子
  • 原文地址:https://www.cnblogs.com/xkops/p/5614366.html
Copyright © 2011-2022 走看看