http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 15603|回复: 5

[教程] Httphelper类网站状态类StatusCode详细说明

[复制链接]
发表于 2013-6-8 08:23:42 | 显示全部楼层 |阅读模式
                            Httphelper类网站状态类StatusCode详细说明
      说到这个,大家可以看看这个文章http://www.sufeinet.com/thread-3563-1-1.html
我希望大这能先区分开一点,网站状态,和网站内容,网站状态和网站内容是没有必然联系的
也就是说状态是状态,内容是内容
说到这里我先列一下Net中网站状态类的所有枚举,大家看一下
[C#] 纯文本查看 复制代码
#region 程序集 System.dll, v4.0.30319
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll
#endregion

using System;

namespace System.Net
{
    // 摘要:
    //     包含为 HTTP 定义的状态代码的值。
    public enum HttpStatusCode
    {
        // 摘要:
        //     Equivalent to HTTP status 100.System.Net.HttpStatusCode.Continue indicates
        //     that the client can continue with its request.
        Continue = 100,
        //
        // 摘要:
        //     Equivalent to HTTP status 101.System.Net.HttpStatusCode.SwitchingProtocols
        //     indicates that the protocol version or protocol is being changed.
        SwitchingProtocols = 101,
        //
        // 摘要:
        //     Equivalent to HTTP status 200.System.Net.HttpStatusCode.OK indicates that
        //     the request succeeded and that the requested information is in the response.这是最常接收的状态代码。
        OK = 200,
        //
        // 摘要:
        //     Equivalent to HTTP status 201.System.Net.HttpStatusCode.Created indicates
        //     that the request resulted in a new resource created before the response was
        //     sent.
        Created = 201,
        //
        // 摘要:
        //     Equivalent to HTTP status 202.System.Net.HttpStatusCode.Accepted indicates
        //     that the request has been accepted for further processing.
        Accepted = 202,
        //
        // 摘要:
        //     Equivalent to HTTP status 203.System.Net.HttpStatusCode.NonAuthoritativeInformation
        //     indicates that the returned metainformation is from a cached copy instead
        //     of the origin server and therefore may be incorrect.
        NonAuthoritativeInformation = 203,
        //
        // 摘要:
        //     Equivalent to HTTP status 204.System.Net.HttpStatusCode.NoContent indicates
        //     that the request has been successfully processed and that the response is
        //     intentionally blank.
        NoContent = 204,
        //
        // 摘要:
        //     Equivalent to HTTP status 205.System.Net.HttpStatusCode.ResetContent indicates
        //     that the client should reset (not reload) the current resource.
        ResetContent = 205,
        //
        // 摘要:
        //     Equivalent to HTTP status 206.System.Net.HttpStatusCode.PartialContent indicates
        //     that the response is a partial response as requested by a GET request that
        //     includes a byte range.
        PartialContent = 206,
        //
        // 摘要:
        //     Equivalent to HTTP status 300.System.Net.HttpStatusCode.MultipleChoices indicates
        //     that the requested information has multiple representations.默认操作是将此状态视为重定向,并遵循与此响应关联的
        //     Location 头的内容。
        MultipleChoices = 300,
        //
        // 摘要:
        //     Equivalent to HTTP status 300.System.Net.HttpStatusCode.Ambiguous indicates
        //     that the requested information has multiple representations.默认操作是将此状态视为重定向,并遵循与此响应关联的
        //     Location 头的内容。
        Ambiguous = 300,
        //
        // 摘要:
        //     Equivalent to HTTP status 301.System.Net.HttpStatusCode.MovedPermanently
        //     indicates that the requested information has been moved to the URI specified
        //     in the Location header.接收到此状态时的默认操作为遵循与响应关联的 Location 头。
        MovedPermanently = 301,
        //
        // 摘要:
        //     Equivalent to HTTP status 301.System.Net.HttpStatusCode.Moved indicates that
        //     the requested information has been moved to the URI specified in the Location
        //     header.接收到此状态时的默认操作为遵循与响应关联的 Location 头。原始请求方法为 POST 时,重定向的请求将使用 GET 方法。
        Moved = 301,
        //
        // 摘要:
        //     Equivalent to HTTP status 302.System.Net.HttpStatusCode.Found indicates that
        //     the requested information is located at the URI specified in the Location
        //     header.接收到此状态时的默认操作为遵循与响应关联的 Location 头。原始请求方法为 POST 时,重定向的请求将使用 GET 方法。
        Found = 302,
        //
        // 摘要:
        //     Equivalent to HTTP status 302.System.Net.HttpStatusCode.Redirect indicates
        //     that the requested information is located at the URI specified in the Location
        //     header.接收到此状态时的默认操作为遵循与响应关联的 Location 头。原始请求方法为 POST 时,重定向的请求将使用 GET 方法。
        Redirect = 302,
        //
        // 摘要:
        //     Equivalent to HTTP status 303.System.Net.HttpStatusCode.SeeOther automatically
        //     redirects the client to the URI specified in the Location header as the result
        //     of a POST.用 GET 生成对 Location 头所指定的资源的请求。
        SeeOther = 303,
        //
        // 摘要:
        //     Equivalent to HTTP status 303.System.Net.HttpStatusCode.RedirectMethod automatically
        //     redirects the client to the URI specified in the Location header as the result
        //     of a POST.用 GET 生成对 Location 头所指定的资源的请求。
        RedirectMethod = 303,
        //
        // 摘要:
        //     Equivalent to HTTP status 304.System.Net.HttpStatusCode.NotModified indicates
        //     that the client's cached copy is up to date.未传输此资源的内容。
        NotModified = 304,
        //
        // 摘要:
        //     Equivalent to HTTP status 305.System.Net.HttpStatusCode.UseProxy indicates
        //     that the request should use the proxy server at the URI specified in the
        //     Location header.
        UseProxy = 305,
        //
        // 摘要:
        //     Equivalent to HTTP status 306.System.Net.HttpStatusCode.Unused is a proposed
        //     extension to the HTTP/1.1 specification that is not fully specified.
        Unused = 306,
        //
        // 摘要:
        //     Equivalent to HTTP status 307.System.Net.HttpStatusCode.TemporaryRedirect
        //     indicates that the request information is located at the URI specified in
        //     the Location header.接收到此状态时的默认操作为遵循与响应关联的 Location 头。原始请求方法为 POST 时,重定向的请求还将使用
        //     POST 方法。
        TemporaryRedirect = 307,
        //
        // 摘要:
        //     Equivalent to HTTP status 307.System.Net.HttpStatusCode.RedirectKeepVerb
        //     indicates that the request information is located at the URI specified in
        //     the Location header.接收到此状态时的默认操作为遵循与响应关联的 Location 头。原始请求方法为 POST 时,重定向的请求还将使用
        //     POST 方法。
        RedirectKeepVerb = 307,
        //
        // 摘要:
        //     Equivalent to HTTP status 400.System.Net.HttpStatusCode.BadRequest indicates
        //     that the request could not be understood by the server.System.Net.HttpStatusCode.BadRequest
        //     is sent when no other error is applicable, or if the exact error is unknown
        //     or does not have its own error code.
        BadRequest = 400,
        //
        // 摘要:
        //     Equivalent to HTTP status 401.System.Net.HttpStatusCode.Unauthorized indicates
        //     that the requested resource requires authentication.WWW-Authenticate 头包含如何执行身份验证的详细信息。
        Unauthorized = 401,
        //
        // 摘要:
        //     Equivalent to HTTP status 402.System.Net.HttpStatusCode.PaymentRequired is
        //     reserved for future use.
        PaymentRequired = 402,
        //
        // 摘要:
        //     Equivalent to HTTP status 403.System.Net.HttpStatusCode.Forbidden indicates
        //     that the server refuses to fulfill the request.
        Forbidden = 403,
        //
        // 摘要:
        //     Equivalent to HTTP status 404.System.Net.HttpStatusCode.NotFound indicates
        //     that the requested resource does not exist on the server.
        NotFound = 404,
        //
        // 摘要:
        //     Equivalent to HTTP status 405.System.Net.HttpStatusCode.MethodNotAllowed
        //     indicates that the request method (POST or GET) is not allowed on the requested
        //     resource.
        MethodNotAllowed = 405,
        //
        // 摘要:
        //     Equivalent to HTTP status 406.System.Net.HttpStatusCode.NotAcceptable indicates
        //     that the client has indicated with Accept headers that it will not accept
        //     any of the available representations of the resource.
        NotAcceptable = 406,
        //
        // 摘要:
        //     Equivalent to HTTP status 407.System.Net.HttpStatusCode.ProxyAuthenticationRequired
        //     indicates that the requested proxy requires authentication.Proxy-authenticate
        //     头包含如何执行身份验证的详细信息。
        ProxyAuthenticationRequired = 407,
        //
        // 摘要:
        //     Equivalent to HTTP status 408.System.Net.HttpStatusCode.RequestTimeout indicates
        //     that the client did not send a request within the time the server was expecting
        //     the request.
        RequestTimeout = 408,
        //
        // 摘要:
        //     Equivalent to HTTP status 409.System.Net.HttpStatusCode.Conflict indicates
        //     that the request could not be carried out because of a conflict on the server.
        Conflict = 409,
        //
        // 摘要:
        //     Equivalent to HTTP status 410.System.Net.HttpStatusCode.Gone indicates that
        //     the requested resource is no longer available.
        Gone = 410,
        //
        // 摘要:
        //     Equivalent to HTTP status 411.System.Net.HttpStatusCode.LengthRequired indicates
        //     that the required Content-length header is missing.
        LengthRequired = 411,
        //
        // 摘要:
        //     Equivalent to HTTP status 412.System.Net.HttpStatusCode.PreconditionFailed
        //     indicates that a condition set for this request failed, and the request cannot
        //     be carried out.条件是用条件请求标头(如 If-Match、If-None-Match 或 If-Unmodified-Since)设置的。
        PreconditionFailed = 412,
        //
        // 摘要:
        //     Equivalent to HTTP status 413.System.Net.HttpStatusCode.RequestEntityTooLarge
        //     indicates that the request is too large for the server to process.
        RequestEntityTooLarge = 413,
        //
        // 摘要:
        //     Equivalent to HTTP status 414.System.Net.HttpStatusCode.RequestUriTooLong
        //     indicates that the URI is too long.
        RequestUriTooLong = 414,
        //
        // 摘要:
        //     Equivalent to HTTP status 415.System.Net.HttpStatusCode.UnsupportedMediaType
        //     indicates that the request is an unsupported type.
        UnsupportedMediaType = 415,
        //
        // 摘要:
        //     Equivalent to HTTP status 416.System.Net.HttpStatusCode.RequestedRangeNotSatisfiable
        //     indicates that the range of data requested from the resource cannot be returned,
        //     either because the beginning of the range is before the beginning of the
        //     resource, or the end of the range is after the end of the resource.
        RequestedRangeNotSatisfiable = 416,
        //
        // 摘要:
        //     Equivalent to HTTP status 417.System.Net.HttpStatusCode.ExpectationFailed
        //     indicates that an expectation given in an Expect header could not be met
        //     by the server.
        ExpectationFailed = 417,
        //
        // 摘要:
        //     Equivalent to HTTP status 500.System.Net.HttpStatusCode.InternalServerError
        //     indicates that a generic error has occurred on the server.
        InternalServerError = 500,
        //
        // 摘要:
        //     Equivalent to HTTP status 501.System.Net.HttpStatusCode.NotImplemented indicates
        //     that the server does not support the requested function.
        NotImplemented = 501,
        //
        // 摘要:
        //     Equivalent to HTTP status 502.System.Net.HttpStatusCode.BadGateway indicates
        //     that an intermediate proxy server received a bad response from another proxy
        //     or the origin server.
        BadGateway = 502,
        //
        // 摘要:
        //     Equivalent to HTTP status 503.System.Net.HttpStatusCode.ServiceUnavailable
        //     indicates that the server is temporarily unavailable, usually due to high
        //     load or maintenance.
        ServiceUnavailable = 503,
        //
        // 摘要:
        //     Equivalent to HTTP status 504.System.Net.HttpStatusCode.GatewayTimeout indicates
        //     that an intermediate proxy server timed out while waiting for a response
        //     from another proxy or the origin server.
        GatewayTimeout = 504,
        //
        // 摘要:
        //     Equivalent to HTTP status 505.System.Net.HttpStatusCode.HttpVersionNotSupported
        //     indicates that the requested HTTP version is not supported by the server.
        HttpVersionNotSupported = 505,
    }
}
[/code]
这些全是网站的状态System.Net.HttpStatusCode类的枚举
200就表示网站状态正常,也就是我们例子中写的Ok
如下
[code=csharp]if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                //表示访问成功,具体的大家就参考HttpStatusCode类
            }

这只是网站状态正常,可并不是网站内容正常哦,所以大家不要能浑了,有的同志跟我讲网站状态是Ok,怎么返回的内容是错误的呢?
这只是状态和内容无关的,接着看
301就是重定向,这个可以参考这里http://www.sufeinet.com/thread-1073-1-1.html
也就是我们平时说的跳转,比如我把sufeinet.com重定向到了www.sufeinet.com这样百度就会把sufeinet.com的权重转移给www.sufeinet.com这样做有助www.sufeinet.com的权重提升。
500之类的就是网站错误了,相信这个大家很常见,
404就是网页找不到,意思就是这个网页不存在
其它的大家自己看看吧。都在上面的类里面
这只是网站状态
这些和网站内容是没有关系的, 比如网站返回是一个正常的Html是200也有可能是301,就算是网站只返回一个1也可能是Ok,也就是说内容和状态是没有必然关系
不能用状态来判断一个网站的内容显示是否正常,
这个现在的办法只有去取里面的关键字,
比如之前有sufeinet这个关键字,后来没有了,那肯定是网站内容有变动,说明是不正常了
所以大家一定要认清楚是要判断网站状态,还是网站内容
如果是网站状态的,那好办,就取上面类里面的枚举进行对比就行了,如果是要判断内容的,就要自己去提取Html内容进行判断了。
好了看了这个文章大家以后就不要分不清网站状态和网站内容了哦

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-6-13 00:11:37 | 显示全部楼层
消灭零回复 受教了,学习中……
发表于 2013-7-12 21:32:50 | 显示全部楼层
表示不懂,不过还是要支持楼主
发表于 2013-9-21 23:26:05 | 显示全部楼层
努力学习ing中, 楼主牛人.很浅显易懂.
发表于 2014-12-20 18:53:56 | 显示全部楼层
C-\]




                                                                                       
发表于 2015-1-13 21:40:21 | 显示全部楼层
楼主的活,很接地气啊!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-23 17:01

© 2014-2021

快速回复 返回顶部 返回列表