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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

楼主: slolitor

[综合] HttpHelper异步版完整实现(附源代码)

[复制链接]
 楼主| 发表于 2014-7-3 17:46:03 | 显示全部楼层
发下.netframework中的一些源码
public class HttpWebRequest : WebRequest, ISerializable
{
//其中一个方法
  private void SubmitRequest(ServicePoint servicePoint);
};

private void SubmitRequest(ServicePoint servicePoint)
{
    if (!this.Async)
    {
        this._ConnectionAResult = new LazyAsyncResult(this, null, null);
        this._ConnectionReaderAResult = new LazyAsyncResult(this, null, null);
        this.OpenWriteSideResponseWindow();
    }
    if ((this._Timer == null) && !this.Async)
    {
        this._Timer = this.TimerQueue.CreateTimer(s_TimeoutCallback, this);
    }
    try
    {
        if ((this._SubmitWriteStream != null) && this._SubmitWriteStream.IsPostStream)
        {
            if ((this._OldSubmitWriteStream == null) && !this._SubmitWriteStream.ErrorInStream)
            {
                this._OldSubmitWriteStream = this._SubmitWriteStream;
            }
            this._WriteBuffer = null;
        }
        this.m_Retry = false;
        if (this.PreAuthenticate)
        {
            if ((this.UsesProxySemantics && (this._Proxy != null)) && (this._Proxy.Credentials != null))
            {
                this.ProxyAuthenticationState.PreAuthIfNeeded(this, this._Proxy.Credentials);
            }
            if (this.Credentials != null)
            {
                this.ServerAuthenticationState.PreAuthIfNeeded(this, this.Credentials);
            }
        }
        if (this.WriteBuffer == null)
        {
            this.UpdateHeaders();
        }
        if (!this.CheckCacheRetrieveBeforeSubmit())
        {
            servicePoint.SubmitRequest(this, this.GetConnectionGroupLine());
        }
    }
    finally
    {
        if (!this.Async)
        {
            this.CheckWriteSideResponseProcessing();
        }
    }
}


internal void SubmitRequest(HttpWebRequest request, string connName)
{
    Connection connection;
    ConnectionGroup group;
    bool forcedsubmit = false;
    lock (this)
    {
        group =this.FindConnectionGroup(connName, false);
    }
    do
    {
        connection = group.FindConnection(request, connName, out forcedsubmit);
    }
    while ((connection != null) && !connection.SubmitRequest(request, forcedsubmit));
}

internal class Connection : PooledStream
{
internal void AbortSocket(bool isAbortState);


internal void AbortSocket(bool isAbortState)
{
    if (isAbortState)
    {
        this.UnlockRequest();
        this.CheckIdle();
    }
    else
    {
        this.m_Error = WebExceptionStatus.KeepAliveFailure;
    }
    lock (this)
    {
       base.Close(0);
    }
}

public void Close(int timeout)
{
    Socket abortSocket = this.m_AbortSocket;
    Socket socket2 = this.m_AbortSocket6;
    this.m_NetworkStream.Close(timeout);
    if (abortSocket != null)
    {
        abortSocket.Close(timeout);
    }
    if (socket2 != null)
    {
        socket2.Close(timeout);
    }
}
















1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2014-7-3 17:47:07 | 显示全部楼层
其实httpwebrequest发送请求就是通过套接字而已 而.net中的套接字如果采用异步,将会封装IOCP的实现,至于用了IOCP会有什么效果 不多说了。
发表于 2014-7-4 10:36:48 | 显示全部楼层
受教了,学习中……
发表于 2014-7-4 12:48:15 | 显示全部楼层
http没必要采用异步吧
发表于 2014-7-5 14:53:40 | 显示全部楼层
请问楼主能放个简单的demo吗,加深实例使用理解
发表于 2014-7-6 17:03:23 | 显示全部楼层
非常感谢你帮了我的大忙,真的太感谢你啦!
 楼主| 发表于 2014-7-7 09:04:09 | 显示全部楼层
什么大忙。。客气客气。。
发表于 2014-7-7 10:05:15 | 显示全部楼层
我调用了异步加载  然后
        private void asyncCallBackMethod(Internet.HttpResult result)
        {
            cookie = result.Cookie;
            MemoryStream ms = new MemoryStream(result.ResultByte);
            Image ii = Image.FromStream(ms);
        }
调用的callback方法  但是里面 不执行了 是怎么回事?
 楼主| 发表于 2014-7-13 13:58:46 | 显示全部楼层
跟踪下堆栈,这么模糊的说明我无法做判断
发表于 2014-7-13 21:28:47 | 显示全部楼层
顶一下了,要
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-4-26 15:51

© 2014-2021

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