苏飞论坛

标题: 极速请求方法FastRequest(极速请求不接收数据)BUG报告 [打印本页]

作者: emile7000    时间: 2014-12-2 06:39
标题: 极速请求方法FastRequest(极速请求不接收数据)BUG报告
FastRequest请求中,未处理请求超时,超时时会报错,请问这种情况应该如何修改?
作者: 站长苏飞    时间: 2014-12-2 08:09
处理的有异常啊,怎么会没有处理呢,都是统一的方法,你说再具体点你的问题,我看看是什么原因
作者: emile7000    时间: 2014-12-2 19:41
站长苏飞 发表于 2014-12-2 08:09
处理的有异常啊,怎么会没有处理呢,都是统一的方法,你说再具体点你的问题,我看看是什么原因

private void t()
        {
            //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://www.baidu.com",//URL     必需项   
                Method = "get",//URL     可选项 默认为Get   
                ContentType = "text/html",//返回类型    可选项有默认值   
                //ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值
            };
            //请求的返回值对象
            HttpResult result = new HttpResult();


            Func<HttpItem, HttpResult> func = http.FastRequest;
            func.BeginInvoke(item, CallViaDelegateCallback, result);
        }

        private void CallViaDelegateCallback(IAsyncResult ar)
        {
            //string str = (string)ar.AsyncState;
            Func<HttpItem, HttpResult> func
                        = (ar as AsyncResult).AsyncDelegate as Func<HttpItem, HttpResult>;
            try
            {
                // 如果有异常,会在这里被重新抛出。
                HttpResult result = func.EndInvoke(ar);
                //状态码
                HttpStatusCode code = result.StatusCode;
                //状态描述
                string Des = result.StatusDescription;
                if (code == HttpStatusCode.OK)
                {
                    int num = Convert.ToInt32(toolStripStatusLabel1.Text) + 1;
                    toolStripStatusLabel1.Text = num.ToString();
                }
               
            }
            catch (Exception ex)
            {
               
            }
        }



然后多循环几次!
private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10000; i++)
            {
                t();
            }
        }


这时候 就会因为没有处理超时  而异常退出
作者: 站长苏飞    时间: 2014-12-2 20:14
这个方法里同不可能有异常报出的,你说的超时更不可能,
我的框架是源码,你可以看的
[C#] 纯文本查看 复制代码
   /// <summary>
        /// 快速Post数据这个访求与GetHtml一样,只是不接收返回数据,只做提交。
        /// </summary>
        /// <param name="item">参数类对象</param>
        /// <returns>返回HttpResult类型</returns>
        internal HttpResult FastRequest(HttpItem item)
        {
            //返回参数
            HttpResult result = new HttpResult();
            try
            {
                //准备参数
                SetRequest(item);
            }
            catch (Exception ex)
            {
                //配置参数时出错
                return new HttpResult() { Cookie = string.Empty, Header = null, Html = ex.Message, StatusDescription = "配置参数时出错:" + ex.Message };
            }
            try
            {
                //请求数据
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    //成功 不做处理只回成功状态
                    return new HttpResult() { Cookie = string.Empty, Header = null, StatusCode = response.StatusCode, StatusDescription = response.StatusDescription };
                }
            }
            catch (WebException ex)
            {
                using (response = (HttpWebResponse)ex.Response)
                {
                    //不做处理只回成功状态
                    return new HttpResult() { Cookie = string.Empty, Header = null, StatusCode = response.StatusCode, StatusDescription = response.StatusDescription };
                }
            }
            catch (Exception ex)
            {
                result.Html = ex.Message;
            }
            if (item.IsToLower) result.Html = result.Html.ToLower();
            return result;
        }

你自己看看源码,怎么可能会报异常,全部都有异常处理的。

这样吧,咱们也不争执了,我说没有是因为我的代码在这里放着,而且我也一直在用,没有出现过这种情况。

如果你感觉是我这里有问题,你就捕获一下异常我看看,

其实很简单的道理,在try
{
}catch

里的代码都不会向外抛出异常,这是C#的基础语法,除非C#本身有问题

那你说有,但是你得让我们看到证据吧,

你的代码异常退出也不一定就是我这部分报的异常吧。





欢迎光临 苏飞论坛 (http://www.sufeinet.com/) Powered by Discuz! X3.4