コード例 #1
0
 /// <summary>
 /// 设置代理
 /// </summary>
 /// <param name="objHttpItems">参数对象</param>
 private void SetProxy(HttpItems objHttpItems)
 {
     //ProxyType.LocalProxy时不进行任何操作
     if (objHttpItems.proxyType == ProxyType.NULL)
     {
         if (!string.IsNullOrEmpty(objHttpItems.ProxyIp))
         {
             WebProxy myProxy;
             //设置代理服务器
             if (objHttpItems.ProxyIp.Contains(":"))
             {
                 string[] plist = objHttpItems.ProxyIp.Split(':');
                 myProxy = new WebProxy(plist[0].Trim(), Convert.ToInt32(plist[1].Trim()));
             }
             else
             {
                 myProxy = new WebProxy(objHttpItems.ProxyIp, false);
             }
             if (!string.IsNullOrEmpty(objHttpItems.ProxyUserName) && !string.IsNullOrEmpty(objHttpItems.ProxyPwd))
             {
                 myProxy.Credentials = new NetworkCredential(objHttpItems.ProxyUserName, objHttpItems.ProxyPwd);
             }
             request.Proxy = myProxy;
             //设置安全凭证
             request.Credentials = CredentialCache.DefaultNetworkCredentials;
         }
         else
         {
             request.Proxy = null;
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// 设置证书
 /// </summary>
 /// <param name="objHttpItems">请求设置参数</param>
 private void SetCer(HttpItems objHttpItems)
 {
     if (!string.IsNullOrEmpty(objHttpItems.CerPath))
     {
         ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
         if (objHttpItems.IsEOFError)
         {
             ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
         }
         //初始化对像,并设置请求的URL地址
         request = (HttpWebRequest)WebRequest.Create(GetUrl(objHttpItems.URL));
         //创建证书文件
         X509Certificate objx509 = new X509Certificate(objHttpItems.CerPath);
         //添加到请求里
         request.ClientCertificates.Add(objx509);
     }
     else
     {
         //初始化对像,并设置请求的URL地址
         try
         {
             request = (HttpWebRequest)WebRequest.Create(GetUrl(objHttpItems.URL));
         }
         catch
         {
             // throw new Exception("请检查输入的网址!");
         }
     }
 }
コード例 #3
0
ファイル: WYEmail.cs プロジェクト: yqMac/regTool
        public void forlog(string cookie,string name,string pwd)
        {
            string url = string.Format("http://reg.email.163.com/unireg/call.do?cmd=register.formLog");
            string[] data =
            {
                string.Format("opt=write_field&flow=main&field=name&result=done&uid={0}%40163.com&timecost={1}&level=info",name,new Random ().Next (4000,10000).ToString () ),
                string.Format ("opt=write_field&flow=main&field=pwd&result=done&strength=2&timecost={0}&level=info",new Random ().Next (4000,10000).ToString ()),
                string.Format ("opt=write_field&flow=main&field=cfmPwd&result=done&timecost={0}&level=info",new Random ().Next (4000,10000).ToString ()),
                string.Format ("opt=write_field&flow=main&field=vcode&result=done&timecost={0}&level=info",new Random ().Next (4000,10000).ToString ()),

             };
            string postdata = "";
            //"opt=write_field&flow=main&field=name&result=done&uid=kljdiel%40163.com&timecost=4460&level=info";
            //opt=write_field&flow=main&field=pwd&result=done&strength=2&timecost=2927&level=info
            //opt=write_field&flow=main&field=cfmPwd&result=done&timecost=2967&level=info
            //opt=write_field&flow=main&field=vcode&result=done&timecost=4920&level=info
            int index = 0;

            while (index < data.Length)
            {
                postdata = data[index];
                index++;

                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                    ProxyIp = Proxy
                };
                hr = helper.GetHtml(items,ref Cookies);
                //Cookies +=  HttpHelpers.GetSmallCookie(hr.Cookie);
                string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
            }
            //reHtml = reHtml.Trim();
        }
コード例 #4
0
 /// <summary>
 /// 设置编码
 /// </summary>
 /// <param name="objHttpItems">Http参数</param>
 private void SetEncoding(HttpItems objHttpItems)
 {
     if (!string.IsNullOrEmpty(objHttpItems.EncodingStr))
     {
         //读取数据时的编码方式
         objHttpItems.Encoding = System.Text.Encoding.GetEncoding(objHttpItems.EncodingStr);
     }
 }
コード例 #5
0
        /// <summary>
        /// 采用httpwebrequest方式访问网络,根据传入的URl地址,得到响应的数据字符串。
        /// </summary>
        /// <param name="objHttpItems">参数列表</param>
        /// <param name="cookie">自动维护的字符串cookie</param>
        /// <returns>HttpResults 为返回结果</returns>
        public HttpResults GetHtml(HttpItems objHttpItems, ref string cookie)
        {
            //调用专门读取数据的类
            HttpResults res = GetHttpRequestData(objHttpItems);

            cookie     = new XJHTTP().UpdateCookie(cookie, res.Cookie);
            res.Cookie = cookie;
            return(res);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: tongwenfei/HttpCodeLib
 private void btnAsyncGet_Click(object sender, EventArgs e)
 {
     HttpHelpers http = new HttpHelpers();//请求发起对象
     HttpItems item = new HttpItems(); //请求设置对象
     System.Net.CookieContainer cc = new System.Net.CookieContainer();//自动处理cookie对象
     item.URL = "bbs.msdn5.com";//请求地址
     item.Container = cc;//初始化cookie
     item.Timeout = 3 * 5000;
     Action<HttpResults> ActionCallback = new Action<HttpResults>(GetCallBack);//完成后的回调地址
     http.AsyncGetHtml(item, ActionCallback);//执行异步请求,结果在ActionCallback的回调函数(GetCallBack)中查看
 }
コード例 #7
0
        /// <summary>
        /// 根据传入的数据,得到相应页面数据
        /// </summary>
        /// <param name="objHttpItems">请求设置参数</param>
        /// <returns>请求结果</returns>
        private HttpResults GetHttpRequestData(HttpItems objHttpItems)
        {
            try
            {
                #region 设置请求参数
                SetRequest(objHttpItems);
                #endregion

                #region 获得应答结果
                response = (HttpWebResponse)request.GetResponse();
                return(GetResponesInfo(ref objHttpItems));

                #endregion
            }
            catch (WebException ex)
            {
                #region 获取异常数据与结果
                result.Html = ex.Message;
                response    = (HttpWebResponse)ex.Response;
                if (response != null)
                {
                    result.StatusCode        = response.StatusCode;
                    result.StatusDescription = ex.Message;
                    try
                    {
                        return(GetResponesInfo(ref objHttpItems));
                    }
                    catch
                    {
                        //释放响应对象 testing
                        response = null;
                        request.Abort();
                        //强制回收
                        System.GC.Collect();
                        return(result);
                    }
                }
                else
                {
                    result.StatusCode        = HttpStatusCode.NotFound;
                    result.StatusDescription = ex.Message;
                }
                #endregion
            }
            return(result);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: tongwenfei/HttpCodeLib
        private void btnGetWebbrowserCookie_Click(object sender, EventArgs e)
        {
            //只能以字符串方式获得
            XJHTTP xjhttp = new XJHTTP();
            string cookie = xjhttp.GetCookieByWininet("https://www.taobao.com");
            HttpHelpers http = new HttpHelpers();
            HttpItems hi = new HttpItems();
            hi = new HttpItems();

            hi.URL = "http://i.taobao.com/my_taobao.htm?spm=a21bo.7724922.1997525045.1.2gOl9t";
            hi.Cookie = cookie;
            hr = http.GetHtml(hi);
            if (hr.Html.Contains("我的淘宝"))
            {
                MessageBox.Show("登录成功");
            }
        }
コード例 #9
0
 /// <summary>
 /// 设置Cookie
 /// </summary>
 /// <param name="objHttpItems">Http参数</param>
 private void SetCookie(HttpItems objHttpItems)
 {
     if (!string.IsNullOrEmpty(objHttpItems.Cookie))
     {
         //字符串方式
         request.Headers[HttpRequestHeader.Cookie] = objHttpItems.Cookie;
     }
     if (objHttpItems.CookieCollection != null)
     {
         //CookieCollection方式
         request.CookieContainer = new CookieContainer();
         request.CookieContainer.Add(objHttpItems.CookieCollection);
     }
     if (objHttpItems.Container != null)
     {
         //CookieContainer方式
         request.CookieContainer = objHttpItems.Container;
     }
 }
コード例 #10
0
        /// <summary>
        ///  根据传入的参数,来异步发起请求
        /// </summary>
        /// <param name="objItems">请求设置参数</param>
        /// <param name="callBack">回调函数</param>
        private void AsyncGetHttpRequestData(HttpItems objItems, Action <HttpResults> callBack)
        {
            AsyncHttpItem hrt = new AsyncHttpItem();

            SetRequest(objItems);
            hrt.objHttpCodeItem = objItems;
            hrt.request         = request;
            hrt.callBack        = callBack;
            try
            {
                IAsyncResult m_ar = hrt.request.BeginGetResponse(AsyncResponseData, hrt);
                System.Threading.ThreadPool.RegisterWaitForSingleObject(m_ar.AsyncWaitHandle,
                                                                        TimeoutCallback, hrt, objItems.Timeout, true);
            }
            catch
            {
                hrt.result.Html = "TimeOut";
            }
        }
コード例 #11
0
 /// <summary>
 /// 设置Post数据
 /// </summary>
 /// <param name="objHttpItems">Http参数</param>
 private void SetPostData(HttpItems objHttpItems)
 {
     //验证在得到结果时是否有传入数据
     if (Regex.IsMatch(request.Method.Trim().ToLower(), "post|delete|put"))
     {
         //写入Byte类型
         if (objHttpItems.PostDataType == PostDataType.Byte)
         {
             //验证在得到结果时是否有传入数据
             //if (objHttpItems.PostdataByte != null && objHttpItems.PostdataByte.Length > 0)
             //{
             request.ContentLength = objHttpItems.PostdataByte.Length;
             request.GetRequestStream().Write(objHttpItems.PostdataByte, 0, objHttpItems.PostdataByte.Length);
             //}
         }//写入文件
         else if (objHttpItems.PostDataType == PostDataType.FilePath)
         {
             using (StreamReader r = new StreamReader(objHttpItems.Postdata, objHttpItems.Encoding))
             {
                 byte[] buffer = objHttpItems.PostEncoding.GetBytes(r.ReadToEnd());
                 request.ContentLength = buffer.Length;
                 request.GetRequestStream().Write(buffer, 0, buffer.Length);
             }
         }
         else
         {
             //if (!string.IsNullOrEmpty(objHttpItems.Postdata))
             //{
             //写入字符串数据.如果希望修改提交时的编码.请修改objHttpItems.PostEncoding
             byte[] buffer = objHttpItems.PostEncoding.GetBytes(objHttpItems.Postdata);
             request.ContentLength = buffer.Length;
             request.GetRequestStream().Write(buffer, 0, buffer.Length);
             //}
         }
     }
 }
コード例 #12
0
ファイル: Form1.cs プロジェクト: tongwenfei/HttpCodeLib
        private void btnGet_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            //初始化Cookie变量
            cc = new System.Net.CookieContainer();
            item = new HttpItems();
            //get 主页
            item.URL = "http://www.mp4ba.com";
            item.Cookie = "__cfduid=123456789; search_state=1463675467;";
            item.UseUnsafe = true;
            hr = http.GetHtml(item);

            string cookie = hr.Cookie;
            XJHTTP xjhttp = new XJHTTP();
            cc = xjhttp.AddCookieToContainer(cc, cookie);
            //get 验证码
            picurl += r.NextDouble();
            item.URL = picurl;
            item.Referer = BaseUrl;
            item.ResultType = ResultType.Byte; //设置返回值类型
            hr = http.GetHtml(item);

            pic.Image = http.GetImg(hr);
        }
コード例 #13
0
        /// <summary>
        /// 识别编码
        /// </summary>
        /// <param name="objHttpItems"></param>
        private void GetEncodingNew(ref HttpItems objHttpItems)
        {
            string temp    = Encoding.Default.GetString(RawResponse, 0, RawResponse.Length);
            Match  meta    = Regex.Match(temp, "<meta([^<]*)charset=([^<]*)[\"']", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            string charter = (meta.Groups.Count > 2) ? meta.Groups[2].Value : string.Empty;

            if (charter.IndexOf("\"") > 0)
            {
                charter = charter.Split('\"')[0];
            }
            if (charter.IndexOf(" ") > 0)
            {
                charter = charter.Split(' ')[0];
            }
            charter = charter.Replace("\"", string.Empty).Replace("'", string.Empty).Replace(";", string.Empty);
            if (charter.Length > 0)
            {
                charter = charter.ToLower().Replace("iso-8859-1", "gbk");
                if (string.IsNullOrEmpty(response.CharacterSet.Trim()) || response.CharacterSet.Trim().Contains("utf"))
                {
                    objHttpItems.Encoding = Encoding.UTF8;
                }
                else
                {
                    Encoding ed = StreamEncoder.GetEncodingFromBytes(RawResponse);
                    if (ed != null)
                    {
                        objHttpItems.Encoding = ed;
                    }
                    else
                    {
                        //强制UTF8
                        objHttpItems.Encoding = Encoding.UTF8;
                    }
                }
            }
            else
            {
                if (response.CharacterSet != null)
                {
                    if (response.CharacterSet.ToLower().Trim() == "iso-8859-1")
                    {
                        // encoding = Encoding.GetEncoding("gbk"); 直接改为UTF8编码
                        objHttpItems.Encoding = Encoding.GetEncoding("gbk");//Encoding.UTF8;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(response.CharacterSet.Trim()) || response.CharacterSet.Trim().Contains("utf"))
                        {
                            objHttpItems.Encoding = Encoding.UTF8;
                        }
                        else
                        {
                            objHttpItems.Encoding = Encoding.GetEncoding(response.CharacterSet);
                        }
                    }
                }
                else
                {
                    Encoding ed = StreamEncoder.GetEncodingFromBytes(RawResponse);
                    if (ed != null)
                    {
                        objHttpItems.Encoding = ed;
                    }
                    else
                    {
                        //强制UTF8
                        objHttpItems.Encoding = Encoding.UTF8;
                    }
                }
            }
        }
コード例 #14
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        /// <summary>
        /// .net
        /// </summary>
        /// <param name="ccc"></param>
        /// <returns></returns>
        private string getRegEmail(CookieContainer ccc)
        {
            HttpItems item = new HttpItems();
            HttpHelpers heler = new HttpHelpers();
            HttpResults hr = new HttpResults();
            string url;

            url = @"https://10minutemail.net/";
            item = new HttpItems()
            {
                URL = url ,
                Container =ccc
            };
            hr = heler.GetHtml(item);
            Regex regex = new Regex("ata-clipboard-text=\".*?\"");
            MatchCollection mc = regex.Matches(hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", ""));
            if (mc != null && mc.Count > 0)
            {

                string email = mc[0].Groups[0].Value;
                email = email.Split(new char[] { '\\', '\"' })[1];
                return email;
            }

            return "";
        }
コード例 #15
0
        /// <summary>
        /// 为请求准备参数
        /// </summary>
        ///<param name="objHttpItems">参数列表</param>
        private void SetRequest(HttpItems objHttpItems)
        {
            //request.KeepAlive = true;
            //request.ProtocolVersion = HttpVersion.Version10;
            // objHttpItems.UseUnsafe = true;
            #region 处理服务器提交协议错误
            if (objHttpItems.UseUnsafe)
            {
                SetAllowUnsafeHeaderParsing20(objHttpItems.UseUnsafe);
            }
            #endregion

            #region 设置证书
            SetCer(objHttpItems);
            #endregion

            #region 设置Header参数 如果有则添加,如果失败,则重置数据
            if (objHttpItems.Header.Count > 0)
            {
                try
                {
                    request.Headers = objHttpItems.Header;
                }
                catch
                {
                    request.Headers = new WebHeaderCollection();
                }
            }

            if (objHttpItems.AutoRedirectMax)
            {
                request.MaximumAutomaticRedirections = 9999;
            }
            #endregion

            #region 添加 Ajax数据头

            if (objHttpItems.IsAjax)
            {
                request.Headers.Add("x-requested-with: XMLHttpRequest");
            }
            #endregion

            #region 设置代理

            SetProxy(objHttpItems);
            #endregion

            #region 通用属性设置
            //请求方式Get或者Post
            request.Method           = objHttpItems.Method;
            request.Timeout          = objHttpItems.Timeout;
            request.ReadWriteTimeout = objHttpItems.ReadWriteTimeout;
            //Accept
            request.Accept = objHttpItems.Accept;
            //ContentType返回类型
            request.ContentType = objHttpItems.ContentType;
            //UserAgent客户端的访问类型,包括浏览器版本和操作系统信息
            request.UserAgent = objHttpItems.UserAgent;


            // 如果设置编码,则从设置结果读取
            SetEncoding(objHttpItems);
            //设置Cookie
            SetCookie(objHttpItems);
            //来源地址
            request.Referer = objHttpItems.Referer;
            //是否执行跳转功能
            request.AllowAutoRedirect = objHttpItems.Allowautoredirect;
            //设置最大连接
            if (objHttpItems.Connectionlimit > 0)
            {
                request.ServicePoint.ConnectionLimit = objHttpItems.Connectionlimit;
                System.Net.ServicePointManager.DefaultConnectionLimit = 1024;
            }
            //设置 post数据在大于1024时是否分包
            request.ServicePoint.Expect100Continue = objHttpItems.Expect100Continue;
            #endregion

            #region 如果当前为Post则设置并提交数据
            SetPostData(objHttpItems);
            #endregion
        }
コード例 #16
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 ///<summary>
 ///采用异步方式访问网络,根据传入的URl地址,得到响应的数据字符串。
 ///</summary>
 ///<param name="objHttpItems">参数列表</param>
 ///<returns>String类型的数据</returns>
 public void AsyncGetHtml(HttpItems objHttpItems, Action<HttpResults> callBack)
 {
     //调用专门读取数据的类
     AsyncGetHttpRequestData(objHttpItems, callBack);
 }
コード例 #17
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 设置代理
 /// </summary>
 /// <param name="objHttpItems">参数对象</param>
 private void SetProxy(HttpItems objHttpItems)
 {
     if (string.IsNullOrEmpty(objHttpItems.ProxyUserName) && string.IsNullOrEmpty(objHttpItems.ProxyPwd) && string.IsNullOrEmpty(objHttpItems.ProxyIp))
     {
         //不需要设置
     }
     else
     {
         //设置代理服务器
         WebProxy myProxy = new WebProxy(objHttpItems.ProxyIp, false);
         //建议连接
         myProxy.Credentials = new NetworkCredential(objHttpItems.ProxyUserName, objHttpItems.ProxyPwd);
         //给当前请求对象
         request.Proxy = myProxy;
         //设置安全凭证
         request.Credentials = CredentialCache.DefaultNetworkCredentials;
     }
 }
コード例 #18
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        private void getUploadRs()
        {
            // Logscomsole(status);
            HttpHelpers helper_up = new HttpHelpers();
            HttpItems items_up = new HttpItems();
            HttpResults hr_up = new HttpResults();
            string url;
            string rehtml;

            url =string.Format ("http://download.csdn.net/my");
            items_up = new HttpItems() {
                URL = url,
                Container = cc
            };
            hr_up = helper_up.GetHtml(items_up);
            string DownHtml = hr_up.Html.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");
            string result = Regex.Replace(DownHtml, @"<!--(.+?)-->", "");

            //获取下载资源数量
            Regex regDown = new Regex("上传资源:<spanclass=\"red\">(.+?)</span>");
            MatchCollection mcDown = regDown.Matches(result);
            double upCount = 0;
            if (mcDown.Count > 0)
            {
                upCount = Convert.ToDouble(mcDown[0].Groups[1].Value);
            }
            //Regex reg = new Regex("<dt><divclass=\"icon\"><imgsrc=\"(.+?)\"title=\"(.+?)\"></div><divclass=\"btns\"></div><h3><ahref=\"(.+?)\"(.*?)\">(.+?)</a><spanclass=\"points\">(.+?)</span></h3></dt>");
            Regex reg = new Regex("<dt><divclass=\"icon\"><imgsrc=\"(.+?)\"title=\"(.+?)\"></div><divclass=\"btns\">(<ahref=(.*?)删除</a>)?</div><h3><ahref=\"(.+?)\"(.*?)\">(.+?)</a><spanclass=\"points\">(.+?)</span></h3></dt>");
            MatchCollection mc = reg.Matches(result);
            if (mc.Count > 0)
            {
                foreach (Match item in mc)
                {
                    CsdnResouce cdsr = new CsdnResouce();
                    if (item.Groups.Count == 9)
                    {
                        cdsr.Url = item.Groups[5].Value;
                        cdsr.Name = item.Groups[7].Value;
                        cdsr.Point = item.Groups[8].Value;
                    }
                    else
                    {
                        cdsr.Url = item.Groups[3].Value;
                        cdsr.Name = item.Groups[5].Value;
                        cdsr.Point = item.Groups[6].Value;
                    }
                    //CsdnResouce cdsr = new CsdnResouce(tmp1[6], tmp1[4]);
                    cdsr.Tag = String.Format("http://download.csdn.net{0}", cdsr.Url);
                    uploadedRS.Add(cdsr );
                }
            }
            Logscomsole(new string[] { "获取上传资源", "结束", "共 " + upCount.ToString() + " 个资源", "", "" });
        }
コード例 #19
0
ファイル: WYEmail.cs プロジェクト: yqMac/regTool
        public bool RegUserPass_Music(string user, string pass, ref string status)
        {
            try
            {
                //http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=163navi%C2%AEPage=163

                //https://ssl.mail.163.com/regall/unireg/prepare.jsp?sid=13B5821160ADE399CD009F3F9AB10EBE&sd=INTERNAL19
                //sid是Cookie中的JSESSIONID

                //验证码
                //http://reg.email.163.com/unireg/call.do?cmd=register.verifyCode&v=common/verifycode/vc_en&env=704864408122&t=1448764801723
                //checkName
                //http://reg.email.163.com/unireg/call.do?cmd=urs.checkName
                //Post
                //name=yqmacmusic

                //https://ssl.mail.163.com/regall/unireg/call.do;jsessionid=13B5821160ADE399CD009F3F9AB10EBE?cmd=register.start
                //name=yqmacmusic&flow=main&uid=yqmacmusic%40163.com&password=yqmacmusic163&confirmPassword=yqmacmusic163&mobile=&vcode=yxysy&from=163navi%C2%AEPage%3D163

                /*name:yqmacmusic
                flow:main
                uid:[email protected]
                password:yqmacmusic163
                confirmPassword:yqmacmusic163
                mobile:
                vcode: yxysy
                from:163navi®Page = 163
              */

                string postData = string.Empty;
                string Vcode = string.Empty;
                byte[] codebytes = null;
                Cookies = "";
                status = string.Empty;
                string cookieForPost = "";
                Cookies = "";
                //获取初始 JSESSIONID,SID两个唯一标识,返回的Cookie里面
                string url = string.Format("http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=163navi%C2%AEPage=163");
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                    ProxyIp = Proxy
                };
                hr = helper.GetHtml(items,ref Cookies);
                string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                if(!reHtml .Contains("注册网易免费邮箱"))
                {
                    status += "获取初始 失败";
                    return false;
                }
                string envalue = get_env(reHtml);

                url = "http://reg.email.163.com/unireg/call.do?cmd=register.formLog";
                postData = string.Format("opt=write_field&flow=main&field=name&result=done&uid={0}%40163.com&timecost={1}&level=info", user , new Random().Next(4000, 10000).ToString());
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                    Method = "post",
                    Postdata =postData ,
                    Referer = "http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=163navi%C2%AEPage=163",
                    // IsAjax = true,
                    ProxyIp = Proxy
                };
                hr = helper.GetHtml(items, ref Cookies);
                reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                reHtml = reHtml.Trim();
                if (!reHtml.Contains("200"))
                {
                    status += "formlog验证,非200";
                    return false;
                }

                if (!CheckUserName(user))
                {
                    status = "检查用户名可注册性返回失败";
                    return false;
                }

                string sid = "";
                sid = GetStringMid(Cookies, "JSESSIONID=", ";");
                string sd = GetStringMid(Cookies, "ser_adapter=", ";");
                if (string.IsNullOrEmpty(sd))
                {
                    sd = Cookies.Substring(Cookies.IndexOf("ser_adapter=") + "ser_adapter=".Length);
                }
                //JSESSIONID=BAF169A63DC82B728981F6A35749F9A0;mailsync=06d9d949febba7cbad54129b7bc6c4671f685c44529e575c78fae60cb5cf36c103fc6b87d5685515a8dc42bce97830b5;ser_adapter=INTERNAL134
                //prepare
                cookieForPost = "";
                url = String.Format("https://ssl.mail.163.com/regall/unireg/prepare.jsp?sid={0}&sd={1}", sid, sd);
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = cookieForPost,
                    ProxyIp = Proxy,
                    //KeepAlive = true,
                    CerPath = System.Environment.CurrentDirectory + @"\163reg.cer",
                    //ProtocolVersion = System.Net.HttpVersion.Version10
                    //IsAjax = true

                };
                //items.CerPath = System.Environment.CurrentDirectory + @"\163reg.cer";
                hr = helper.GetHtml(items, ref cookieForPost);
                GETVCODE:

                //获取验证码数据

                url = String.Format("http://reg.email.163.com/unireg/call.do?cmd=register.verifyCode&v=common/verifycode/vc_en&env={0}&t={1}", envalue, new XJHTTP().GetTimeByJs());
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                    ProxyIp = Proxy,
                    ResultType = ResultType.Byte
                };

                hr = helper.GetHtml(items,ref Cookies );
                //Cookies +=  HttpHelpers.GetSmallCookie(hr.Cookie);
                codebytes = hr.ResultByte;
                //获取验证码
                if (codebytes.Length < 100 || getImgCode == null || codebytes == null || string.IsNullOrEmpty(Vcode = getImgCode(codebytes)))
                {
                    string str = System.Text.Encoding.Default.GetString(codebytes);
                    str = GetStringMid(str, "msg\":\"", "\"");
                    status = "验证码识别有问题:" + str;
                    //status += hr.Html;
                    return false;
                }

                forlog(Cookies ,user ,pass );

                //JSESSIONID=BAF169A63DC82B728981F6A35749F9A0;mailsync=562d05ee8ccf61a2b72091d6f755dc026cce72127aef931f1a82e260197506399c1fe6c90e59d1dfa8dc42bce97830b5;ser_adapter=INTERNAL134

                //JSESSIONID=BAF169A63DC82B728981F6A35749F9A0;mailsync=562d05ee8ccf61a2b72091d6f755dc026cce72127aef931f1a82e260197506399c1fe6c90e59d1dfa8dc42bce97830b5;ser_adapter=INTERNAL134
                //Cookies +=  HttpHelpers.GetSmallCookie(hr.Cookie);
                //reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
               // Cookies =Cookies.Replace(";;",";");

                //正式提交注册数据
                url = String.Format("https://ssl.mail.163.com/regall/unireg/call.do;jsessionid={0}?cmd=register.start", sid);
                postData = String.Format(
                    "name={0}&flow=main&uid={1}%40163.com&password={2}&confirmPassword={3}&mobile=&vcode={4}&from=163navi%C2%AEPage%3D163"
                    , user, user, pass, pass, Vcode);
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = cookieForPost,
                    ProxyIp = Proxy,
                    Method = "POST",
                    //PostDataType = CsharpHttpHelpers.Enum.PostDataType.String,
                    Postdata = postData,
                    //KeepAlive =true ,
                    Referer = "http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=163navi%C2%AEPage=163",
                    Allowautoredirect = false ,
                    //IsAjax =true ,
                    CerPath = System.Environment.CurrentDirectory + @"\163reg.cer",
                    //ProtocolVersion = System.Net.HttpVersion.Version10
                };
                hr = helper.GetHtml(items,ref cookieForPost);
               // Cookies +=  HttpHelpers.GetSmallCookie(hr.Cookie);
                reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                reHtml = reHtml.Trim();

                ////Cookies = HttpHelpers.GetSmallCookie(Cookies );
                // url = string.Format("http://entry.mail.163.com/coremail/fcg/ntesdoor2");
                //items = new HttpItems()
                //{
                //    URL = url,
                //    Cookie = Cookies,
                //    ProxyIp = Proxy
                //};
                //hr = helper.GetHtml(items,ref Cookies);
                ////Cookies +=  HttpHelpers.GetSmallCookie(hr.Cookie);
                // reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                ////reHtml = reHtml.Trim();
                //if (reHtml == "无法连接到远程服务器")
                //{
                //    status += "无法连接到远程服务器";
                //    return false;
                //}

                //{"code":401,"desc":"PARAMETER ERROR","msg":"VCODE_NOT_MATCH","result":863675}
                if (cookieForPost.Contains ("NTES_SESS") ||reHtml.Contains("注册成功") || reHtml.Contains("http://mail.163.com/dashi/activity/reg/ok.do?from=zimu"))
                {
                    File.AppendAllText(Environment.CurrentDirectory + @"\finishUsers.txt", string.Format("{0}----{1}\r\n", user, pass));
                    status += "注册成功\t";
                    Cookies = cookieForPost;
                    return true;
                    //MessageBox.Show("注册成功");
                }
                else
                {
                    yq.LogHelper.Debug("user :"******";pass:"******";msg" + reHtml);
                    string msg = GetStringMid(reHtml, "msg\":\"", "\"");
                    switch (string.IsNullOrEmpty(msg) ? reHtml : msg)
                    {
                        case "INVALID NAME":
                            status += "无效的用户名";
                            break;
                        case "NAME_EQUALS_PASSWORD":
                            status += "密码和用户名不能完全相同";
                            break;
                        case "NO_PASSWORD":
                            break;
                        case "NAME EQUALS PASSWORD":
                        case "PASSWORD TOO SIMPLE":
                            status += "密码过于简单,请尝试“字母+数字”的组合";
                            break;
                        case "NO_CONFIRMED_PASSWORD":
                        case "PASSWORD_NOT_MATCH":
                            break;
                        case "INVALID MOBILE":
                            status += "请填写有效的11位手机号码";
                            break;
                        case "BIND TOO MANY":
                            status += "该手机号码已绑定5个帐号,请编辑短信“JC”发送到 10690163331,取消手机和所有帐号的绑定关系";
                            break;
                        case "VCODE_NOT_MATCH":
                            goto GETVCODE;
                        default:
                            status += reHtml;
                            break;
                    }
                    return false;
                    //MessageBox.Show(reHtml);
                }
            }
            catch (Exception ex)
            {
            }
            /*
            this.handleMsg = function(U) {
            switch (U.msg) {
            case "INVALID NAME":
            d.showRemind("error", "name", "无效的用户名");
            j.name = false;
            break;
            case "ILLEGAL_UID":
            $("#nameIpt").blur();
            j.name = false;
            break;
            case "NAME_EQUALS_PASSWORD":
            d.showRemind("error", "mainPwd", "密码和用户名不能完全相同");
            j.pwd = false;
            break;
            case "NO_PASSWORD":
            $("#mainPwdIpt").blur();
            j.pwd = false;
            break;
            case "NAME EQUALS PASSWORD":
            case "PASSWORD TOO SIMPLE":
            d.showRemind("error", "mainPwd", "密码过于简单,请尝试“字母+数字”的组合");
            j.pwd = false;
            break;
            case "NO_CONFIRMED_PASSWORD":
            case "PASSWORD_NOT_MATCH":
            $("#mainCfwPwdIpt").blur();
            j.cfmPwd = false;
            break;
            case "INVALID MOBILE":
            d.showRemind("error", "mainMobile", "请填写有效的11位手机号码");
            j.mobile = false;
            break;
            case "BIND TOO MANY":
            d.showRemind("error", "mainMobile", "该手机号码已绑定5个帐号,请编辑短信“JC”发送到 10690163331,取消手机和所有帐号的绑定关系");
            j.mobile = false;
            break;
            case "VCODE_NOT_MATCH":
            d.showRemind("error", "vcode", "验证码不正确,请重新填写");
            if (U.result) {
                f.initEnv(U.result)
            }
            $("#vcodeImg").click();
            j.vcode = false;
            break;
            case "INVALID_SUSPEND":
            case "REGISTER_NOT_FOUND":
            $("#overdueTips").show();
            break;
            default:
            $("#overdueTips").show();
            break
            }
            */
            return false;
        }
コード例 #20
0
ファイル: WYEmail.cs プロジェクト: yqMac/regTool
 public Email163()
 {
     helper = new HttpHelpers();
     items = new HttpItems();
 }
コード例 #21
0
ファイル: WYEmail.cs プロジェクト: yqMac/regTool
        public bool Login163(string user,string pwd)
        {
            Cookies = "";
            string url = "";
            string postdata = "";
            string reHtml = "";
            try
            {
                //获取浏览器标识JESSION等基础信息
                url = string.Format("http://reg.163.com/click.jsp?click_in=Login&v={0}&click_count_spec=userLoginQuery&_ahref=&_at=",new XJHTTP ().GetTimeByJs ());
                items = new HttpItems() {
                    URL =url,
                    Cookie =Cookies,
                    Referer=string.Format ("http://reg.163.com/UserLogin.do?errorType=460&errorUsername={0}@163.com",user )//"http://reg.163.com/UserLogin.do"
                };
                hr = helper.GetHtml(items ,ref Cookies );
                reHtml = hr.Html;

                //提交登录信息
                url = string.Format("https://reg.163.com/logins.jsp");
                postdata = string.Format("type=1&product=urs&url=&url2=http%3A%2F%2Freg.163.com%2FUserLogin.do&username={0}%40163.com&password={1}",user ,pwd );
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                    Method ="post",
                    Postdata =postdata,
                     Referer = string.Format("http://reg.163.com/UserLogin.do?errorType=460&errorUsername={0}@163.com", user)
                };
                hr = helper.GetHtml(items, ref Cookies);
                reHtml = hr.Html;

                //登录后面内容
                url = string.Format("http://reg.163.com/Main.jsp?username={0}",user );
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                };
                hr = helper.GetHtml(items, ref Cookies);
                reHtml = hr.Html;

                if (reHtml.Contains("上次登录")) {
                    return true;
                }
            }

            catch (Exception ex)
            {

            }

            return false;
        }
コード例 #22
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        private string activeRegEmai2(string emailname,CookieContainer ccc)
        {
            string reText = "";
            string[] status = { "操作", "成功/失败", "状态信息", "无验证码", "无附加信息" };
            Thread.Sleep(15000);
            HttpItems item = new HttpItems();
            HttpHelpers heler = new HttpHelpers();
            HttpResults hr = new HttpResults();
            Regex regex = null;
            MatchCollection mc = null;
            int trytimes = 0;
            string emalid="";
            emalid = emailname .Substring (0,emailname .IndexOf ('@'));
            item = new HttpItems();
            //https://10minutemail.net/
            item.URL = @"http://mailcatch.com/en/rpc.lua";
            item.Method = "Post";
            item.Postdata = string.Format("mod=ListMailsRPC&fct=List&json=%7B%22box%22%3A%22{0}%3Dmailcatch.com%22%2C%22anim%22%3Atrue%7D",emalid );//@"AJAXREQUEST=j_id3&j_id4=j_id4&javax.faces.ViewState=j_id42162&j_id4%3Apoll=j_id4%3Apoll&";
            item.Container = ccc;
            item.Allowautoredirect = true;
            hr = heler.GetHtml(item);
            string emalurl = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
            if ("errorerror".Equals(emalurl))
            {
                return "失败:errorerror";
            }
            //?box=$boxid&show=a134fc9d-5412-4cda-ac7e-04b48103f78f\">[CSDN

            regex = new Regex("\\&show=(.*?)\\\"\\>\\[CSDN");
            mc = regex.Matches(emalurl);
            if (mc != null && mc.Count >= 1)
            {
                status[0] = "注册帐号";
                status[1] = "进行中";
                status[2] = "扫描到激活邮件";
                status[3] = "即将完成申请";
                status[4] = "";
                Logscomsole(status);
                string []strtmp=mc[0].Groups[0].Value.Split(new char[] { '\"','\\' });
                string urltmp = string.Format("http://yourinbox.mailcatch.com/en/temporary-inbox?box={0}=mailcatch.com{1}", emalid, strtmp[0]);// +"lang=zh-cn";
                //Console.WriteLine(urltmp );
                item = new HttpItems();
                item.URL = urltmp;
                item.Container = ccc;
                item.Allowautoredirect = true;
                hr = heler.GetHtml(item);
                emalurl = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");

                regex = new Regex("https://passport.csdn.net(.*?)action=userInfoView");
                mc = regex.Matches(emalurl);
                if (mc != null && mc.Count > 0)
                {
                    string urlacc = mc[0].Groups[0].Value.Replace("&amp;", "&");
                    return urlacc;
                    //string urlacc = mc[0].Groups[0].Value.Split(new char[] { '\"' })[1]; ;
                    item = new HttpItems();
                    item.URL = urlacc;
                    item.Container = new CookieContainer();
                    hr = heler.GetHtml(item);
                    string htmlss = hr.Html;
                    if (htmlss.Contains("注册成功"))
                    {
                        return "注册成功";
                    }
                    else
                    {
                        return "注册失败" + htmlss;
                    }
                }
            }

            return "注册失败";
        }
コード例 #23
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        private string activeRegEmai1(CookieContainer ccc)
        {
            string reText = "";
            string[] status = { "操作", "成功/失败", "状态信息", "无验证码", "无附加信息" };

            HttpItems item = new HttpItems();
            HttpHelpers heler = new HttpHelpers();
            HttpResults hr = new HttpResults();
            Regex regex = null;
            MatchCollection mc = null;
            int trytimes = 0;

            item = new HttpItems();
            //https://10minutemail.net/
            item.URL = @"http://10minutemail.com/10MinuteMail/index.html";
            item.Method = "Post";
            item.Postdata = @"AJAXREQUEST=j_id3&j_id4=j_id4&javax.faces.ViewState=j_id42162&j_id4%3Apoll=j_id4%3Apoll&";
            item.Container = ccc;
            item.Allowautoredirect = true;
            CHECKEMAIL:
            hr = heler.GetHtml(item);
            string emalurl = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
            if ("errorerror".Equals(emalurl))
            {
                return "失败:errorerror";
            }
            regex = new Regex("<td>service@register\\.csdn.net</td><td><a href=\".*?\">\\[CSDN\\]");
            mc = regex.Matches(emalurl);

            if (mc.Count == 0)
            {
                if (trytimes <= 10)
                {
                    trytimes++;
                    status[0] = "注册帐号";
                    status[1] = "进行中";
                    status[2] = "等待邮件到达";
                    status[3] = "20秒后重新扫描";
                    status[4] = "";
                    Logscomsole(status);
                    Thread.Sleep(20000);
                    goto CHECKEMAIL;
                }
                else
                {
                    status[0] = "注册帐号";
                    status[1] = "失败";
                    status[2] = "邮件长时间未到";
                    status[3] = "重试申请";
                    status[4] = "";
                    Logscomsole(status);
                    //reg();
                    return "邮件长时间未到";
                }

            }
            if (mc != null && mc.Count >= 1)
            {
                status[0] = "注册帐号";
                status[1] = "进行中";
                status[2] = "扫描到激活邮件";
                status[3] = "即将完成申请";
                status[4] = "";
                Logscomsole(status);

                string urltmp = @"http://10minutemail.com/" + mc[0].Groups[0].Value.Split(new char[] { '\"' })[1].Replace ("&amp;","&");// +"lang=zh-cn";
                //Console.WriteLine(urltmp );
                item = new HttpItems();
                item.URL = urltmp;
                item.Container = ccc;
                item.Allowautoredirect=true;
                hr = heler.GetHtml(item);
                emalurl = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                // Console.WriteLine(emalurl);
                //action=userInfoView
                //regex = new Regex("CSDN各项服务。<br/><br/> https(.*?)<br/>");

                regex = new Regex("https://passport.csdn.net(.*?)action=userInfoView");
                mc = regex.Matches(emalurl);
                if (mc != null && mc.Count > 0)
                {
                    string urlacc = mc[0].Groups[0].Value.Replace("&amp;", "&");
                    //string urlacc = mc[0].Groups[0].Value.Split(new char[] { '\"' })[1]; ;
                    item = new HttpItems();
                    item.URL = urlacc;
                    item.Container = new CookieContainer();
                    hr = heler.GetHtml(item);
                    string htmlss = hr.Html;
                    if (htmlss.Contains("注册成功"))
                    {
                        return "注册成功";
                    }
                    else
                    {
                        return "注册失败" + htmlss;
                    }
                }
            }

            return "注册失败";
        }
コード例 #24
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        /// <summary>
        /// .net
        /// </summary>
        /// <param name="ccc"></param>
        /// <returns></returns>
        private string activeRegEmai(CookieContainer ccc)
        {
            string reText = "";
            string[] status = { "操作", "成功/失败", "状态信息", "无验证码", "无附加信息" };

            HttpItems item = new HttpItems();
            HttpHelpers heler = new HttpHelpers();
            HttpResults hr = new HttpResults();
            Regex regex = null ;
            MatchCollection mc = null;
            int trytimes = 0;

            item = new HttpItems();
            //https://10minutemail.net/
            item.URL = @"https://10minutemail.net/mailbox.ajax.php?_=";

            item.Container = ccc ;
             CHECKEMAIL:
            hr = heler.GetHtml(item);
            string emalurl = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
            if ("errorerror".Equals(emalurl))
            {
                return "失败:errorerror";
            }
            regex = new Regex("<td>service@register\\.csdn.net</td><td><a href=\".*?\">\\[CSDN\\]");
            mc = regex.Matches(emalurl);

            if (mc.Count == 0)
            {
                if (trytimes <= 10)
                {
                    trytimes++;
                    status[0] = "注册帐号";
                    status[1] = "进行中";
                    status[2] = "等待邮件到达";
                    status[3] = "20秒后重新扫描";
                    status[4] = "";
                    Logscomsole(status);
                    Thread.Sleep(20000);
                    goto CHECKEMAIL;
                }
                else
                {
                    status[0] = "注册帐号";
                    status[1] = "失败";
                    status[2] = "邮件长时间未到";
                    status[3] = "重试申请";
                    status[4] = "";
                    Logscomsole(status);
                    //reg();
                    return "邮件长时间未到";
                }

            }
            if (mc != null && mc.Count >= 1)
            {
                status[0] = "注册帐号";
                status[1] = "进行中";
                status[2] = "扫描到激活邮件";
                status[3] = "即将完成申请";
                status[4] = "";
                Logscomsole(status);

                string urltmp = @"https://10minutemail.net/" + mc[0].Groups[0].Value.Split(new char[] { '\"' })[1];// +"lang=zh-cn";
                //Console.WriteLine(urltmp );
                item = new HttpItems();
                item.URL = urltmp;
                item.Container =ccc ;
                hr  = heler .GetHtml(item);
                emalurl = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                // Console.WriteLine(emalurl);
                regex = new Regex("href=\".*?\"");
                mc = regex.Matches(emalurl);
                if (mc != null && mc.Count > 0)
                {
                    string urlacc = mc[103].Groups[0].Value.Split(new char[] { '\"' })[1].Replace("&amp;", "&"); ;
                    item = new HttpItems();
                    item.URL = urlacc;
                    item.Container = new CookieContainer ();
                    hr = heler.GetHtml(item);
                    string htmlss = hr.Html;
                    if (htmlss.Contains("注册成功"))
                    {
                        return "注册成功";
                    }
                    else
                    {
                        return "注册失败"+htmlss;
                    }
                }
            }

            return "注册失败" ;
        }
コード例 #25
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 设置Post数据
 /// </summary>
 /// <param name="objHttpItems">Http参数</param>
 private void SetPostData(HttpItems objHttpItems)
 {
     //验证在得到结果时是否有传入数据
     if (request.Method.Trim().ToLower().Contains("post"))
     {
         //写入Byte类型
         if (objHttpItems.PostDataType == PostDataType.Byte)
         {
             //验证在得到结果时是否有传入数据
             if (objHttpItems.PostdataByte != null && objHttpItems.PostdataByte.Length > 0)
             {
                 request.ContentLength = objHttpItems.PostdataByte.Length;
                 request.GetRequestStream().Write(objHttpItems.PostdataByte, 0, objHttpItems.PostdataByte.Length);
             }
         }//写入文件
         else if (objHttpItems.PostDataType == PostDataType.FilePath)
         {
             StreamReader r = new StreamReader(objHttpItems.Postdata, encoding);
             byte[] buffer = Encoding.Default.GetBytes(r.ReadToEnd());
             r.Close();
             request.ContentLength = buffer.Length;
             request.GetRequestStream().Write(buffer, 0, buffer.Length);
         }
         else
         {
             //验证在得到结果时是否有传入数据
             if (!string.IsNullOrEmpty(objHttpItems.Postdata))
             {
                 byte[] buffer = Encoding.Default.GetBytes(objHttpItems.Postdata);
                 request.ContentLength = buffer.Length;
                 request.GetRequestStream().Write(buffer, 0, buffer.Length);
             }
         }
     }
 }
コード例 #26
0
ファイル: WYEmail.cs プロジェクト: yqMac/regTool
        /// <summary>
        /// 检查某用户名可否被注册
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        private bool CheckUserName(string username)
        {
            try
            {
                string url = String.Format("http://reg.email.163.com/unireg/call.do?cmd=urs.checkName");
                string postdata = "name="+username ;
                items = new HttpItems()
                {
                    URL = url,
                    Cookie = Cookies,
                    Method = "post",
                    Postdata = postdata,
                    IsAjax = true

                };
                //items.Container = cc;
                // items.ProxyIp = proxy ;
                hr = helper.GetHtml(items,ref Cookies);
                //Cookies +=  HttpHelpers.GetSmallCookie(hr.Cookie);
                string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");
                reHtml = reHtml.Trim();
                //Cookiesss += hr.Cookie;
                if (reHtml.Contains("OK"))
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
            }

            return false;
        }
コード例 #27
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 ///<summary>
 ///采用https协议访问网络,根据传入的URl地址,得到响应的数据字符串。
 ///</summary>
 ///<param name="objHttpItems">参数列表</param>
 ///<returns>String类型的数据</returns>
 public HttpResults GetHtml(HttpItems objHttpItems)
 {
     //准备参数
     SetRequest(objHttpItems);
     //调用专门读取数据的类
     return GetHttpRequestData(objHttpItems);
 }
コード例 #28
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 获取当前请求所有Cookie
 /// </summary>
 /// <param name="items"></param>
 /// <returns>Cookie集合</returns>
 public List<Cookie> GetAllCookieByHttpItems(HttpItems items)
 {
     return wnet.GetAllCookies(items.Container);
 }
コード例 #29
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
        /// <summary>
        /// 根据相传入的数据,得到相应页面数据
        /// </summary>
        /// <param name="strPostdata">传入的数据Post方式,get方式传NUll或者空字符串都可以</param>
        /// <returns>string类型的响应数据</returns>
        private HttpResults GetHttpRequestData(HttpItems objHttpItems)
        {
            //返回参数
            HttpResults result = new HttpResults();
            try
            {
                #region 得到请求的response

                result.CookieCollection = new CookieCollection();
                response = (HttpWebResponse)request.GetResponse();

                result.Header = response.Headers;
                if (response.Cookies != null)
                {
                    result.CookieCollection = response.Cookies;
                }
                if (response.Headers["set-cookie"] != null)
                {
                    result.Cookie = response.Headers["set-cookie"];
                }
                //处理返回值Container
                result.Container = objHttpItems.Container;
                MemoryStream _stream = new MemoryStream();
                //GZIIP处理
                if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
                {
                    _stream = GetMemoryStream(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress));
                }
                else
                {
                    _stream = GetMemoryStream(response.GetResponseStream());
                }
                //获取Byte
                byte[] RawResponse = _stream.ToArray();
                //是否返回Byte类型数据
                if (objHttpItems.ResultType == ResultType.Byte)
                {
                    result.ResultByte = RawResponse;
                    return result;
                }
                //无视编码
                if (encoding == null)
                {
                    string temp = Encoding.Default.GetString(RawResponse, 0, RawResponse.Length);
                    //<meta(.*?)charset([\s]?)=[^>](.*?)>
                    Match meta = Regex.Match(temp, "<meta([^<]*)charset=([^<]*)[\"']", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    string charter = (meta.Groups.Count > 2) ? meta.Groups[2].Value : string.Empty;
                    charter = charter.Replace("\"", string.Empty).Replace("'", string.Empty).Replace(";", string.Empty);
                    if (charter.Length > 0)
                    {
                        charter = charter.ToLower().Replace("iso-8859-1", "gbk");
                        encoding = Encoding.GetEncoding(charter);
                    }
                    else
                    {
                        if (response.CharacterSet != null)
                        {
                            if (response.CharacterSet.ToLower().Trim() == "iso-8859-1")
                            {
                                encoding = Encoding.GetEncoding("gbk");
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(response.CharacterSet.Trim()))
                                {
                                    encoding = Encoding.UTF8;
                                }
                                else
                                {
                                    encoding = Encoding.GetEncoding(response.CharacterSet);
                                }
                            }
                        }
                    }
                }
                //得到返回的HTML
                try
                {
                    if (RawResponse.Length > 0)
                    {
                        result.Html = encoding.GetString(RawResponse);
                    }
                    else
                    {
                        result.Html = "";
                    }
                    _stream.Close();
                    response.Close();
                }
                catch
                {
                    return null;
                }
                //最后释放流

                #endregion 得到请求的response
            }
            catch (WebException ex)
            {
                //这里是在发生异常时返回的错误信息
                result.Html = "String Error";
                response = (HttpWebResponse)ex.Response;
                return result;
            }
            if (objHttpItems.IsToLower)
            {
                result.Html = result.Html.ToLower();
            }
            return result;
        }
コード例 #30
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 异步GET请求 通过回调返回结果
 /// </summary>
 /// <param name="objHttpItems">请求项</param>
 /// <param name="callBack">回调地址</param>
 public void AsyncGetHtml(HttpItems objHttpItems, Action<HttpResults> callBack)
 {
     http.AsyncGetHtml(objHttpItems, callBack);
 }
コード例 #31
0
ファイル: Form1.cs プロジェクト: yqMac/regTool
        private void waitforIp(string ip)
        {
            bool retry = true ;
            do
            {
                HttpItems items = new HttpItems();
                items.URL = @"http://www.ip138.com/ips1388.asp";
                //items.ProxyIp = ip;
                items.Cookie = " ";
                //items.ProxyIp = "";
                items.Timeout = 3000;
                HttpResults hr = new HttpHelpers().GetHtml(items);
                //string s = hr.StatusDescription;

                string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "").Replace(" ", "");
                if (reHtml.Contains("您的IP地址是"))
                {
                    retry = false;
                    reHtml = new XJHTTP().GetStringMid(reHtml, "您的IP地址是:[", "]");
                    //reHtml = new XJHTTP().GetStringMid(reHtml, "[", "");
                }
                else
                {
                    Tsleep(10);
                }
            }
            while (retry);
        }
コード例 #32
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 根据相传入的数据,得到相应页面数据
 /// </summary>
 /// <param name="strPostdata">传入的数据Post方式,get方式传NUll或者空字符串都可以</param>
 /// <returns>string类型的响应数据</returns>
 private void AsyncGetHttpRequestData(HttpItems objItems, Action<HttpResults> callBack)
 {
     HttpRequest hrt = new HttpRequest();
     SetRequest(objItems);
     hrt.objHttpCodeItem = objItems;
     hrt.request = request;
     hrt.callBack = callBack;
     try
     {
         IAsyncResult m_ar = hrt.request.BeginGetResponse(AsyncResponseData, hrt);
         System.Threading.ThreadPool.RegisterWaitForSingleObject(m_ar.AsyncWaitHandle,
             TimeoutCallback, hrt, HttpRequest.DefaultTimeOutSpan, true);
     }
     catch (Exception ex)
     {
         hrt.result.Html = "TimeOut";
     }
 }
コード例 #33
0
        /// <summary>
        /// 处理响应结果
        /// </summary>
        /// <param name="objHttpItems">请求设置参数</param>
        /// <returns></returns>
        private HttpResults GetResponesInfo(ref HttpItems objHttpItems)
        {
            #region 设置返回结果
            result.StatusCode        = response.StatusCode;
            result.StatusDescription = response.StatusDescription;
            result.Header            = response.Headers;
            if (response.Cookies != null)
            {
                result.CookieCollection = response.Cookies;
            }
            if (response.ResponseUri != null)
            {
                result.ResponseUrl = response.ResponseUri.ToString();
            }
            if (response.Headers["set-cookie"] != null)
            {
                //清理垃圾Cookie信息
                result.Cookie    = new XJHTTP().ClearCookie(response.Headers["set-cookie"]);
                result.RawCookie = response.Headers["set-cookie"];
            }
            //处理返回值Container
            result.Container = objHttpItems.Container;
            #endregion

            #region 急速请求,不解析结果数据

            if (objHttpItems.ResultType == ResultType.So)
            {
                return(result);
            }
            #endregion

            #region 应答结果转换为内存数据

            using (_stream = new MemoryStream())
            {
                //GZIIP处理
                if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
                {
                    _stream = GetMemoryStream(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress));
                }
                else if (response.ContentEncoding != null && response.ContentEncoding.Equals("Deflate", StringComparison.InvariantCultureIgnoreCase))
                {
                    //处理 Deflate
                    _stream = GetMemoryStream(new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress));
                }
                else
                {
                    _stream = GetMemoryStream(response.GetResponseStream());
                }
                //获取Byte
                RawResponse = _stream.ToArray();
            }
            #endregion

            #region 如果设置返回结果类型则返回Byte数据

            if (objHttpItems.ResultType == ResultType.Byte)
            {
                result.ResultByte = RawResponse;
                return(result);
            }
            #endregion

            #region 处理编码结果

            if (objHttpItems.Encoding == null)//如果用户没有指定编码格式
            {
                try
                {
                    //Encoding ed = StreamEncoder.GetEncodingFromBytes(RawResponse);
                    //if (ed != null)
                    //{
                    //    objHttpItems.Encoding = ed;
                    //}
                    //else
                    //{
                    GetEncodingNew(ref objHttpItems);
                    //}
                }
                catch
                {
                    //强制UTF8
                    objHttpItems.Encoding = Encoding.UTF8;
                }
            }
            //得到返回的HTML
            try
            {
                if (RawResponse.Length > 0)
                {
                    result.Html = objHttpItems.Encoding.GetString(RawResponse);
                }
                else
                {
                    result.Html = "HttpCode接收数据长度为0.请检查数据包.当前状态码:" + result.StatusCodeNum.ToString() + result.Html;
                }
            }
            catch (Exception exp)
            {
                result.Html = "HttpCode接收数据出现异常..请检查数据包.当前状态码:" + result.StatusCodeNum.ToString() + result.Html + "异常信息: " + exp.ToString();
            }

            #endregion
            //释放响应对象 testing
            response.Close();
            response = null;
            request.Abort();
            //强制回收
            System.GC.Collect();
            return(result);
        }
コード例 #34
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        private string getRegEmail2(CookieContainer ccc)
        {
            HttpItems item = new HttpItems();
            HttpHelpers heler = new HttpHelpers();
            HttpResults hr = new HttpResults();

            item = new HttpItems();
            //http://10minutemail.com/10MinuteMail/index.html
            item.URL = @"http://mailcatch.com/en/disposable-email";
            item.Container = ccc;

            hr = heler.GetHtml(item);
            Regex regex = new Regex("ata-clipboard-text=\".*?\"");
            MatchCollection mc = regex.Matches(hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", ""));
            if (mc != null && mc.Count > 0)
            {

                string email = mc[0].Groups[0].Value;
                email = email.Split(new char[] { '\\', '\"' })[1];
                return email;
            }

            return "";
        }
コード例 #35
0
 /// <summary>
 /// 采用异步方式访问网络,根据传入的URl地址,得到响应的数据字符串。
 /// </summary>
 /// <param name="objHttpItems">参数列表</param>
 /// <param name="callBack">完成后的回调函数</param>
 public void AsyncGetHtml(HttpItems objHttpItems, Action <HttpResults> callBack)
 {
     //调用专门读取数据的类
     AsyncGetHttpRequestData(objHttpItems, callBack);
 }
コード例 #36
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 设置编码
 /// </summary>
 /// <param name="objHttpItems">Http参数</param>
 private void SetEncoding(HttpItems objHttpItems)
 {
     if (string.IsNullOrEmpty(objHttpItems.Encoding) || objHttpItems.Encoding.ToLower().Trim() == "null")
     {
         //读取数据时的编码方式
         encoding = null;
     }
     else
     {
         //读取数据时的编码方式
         encoding = System.Text.Encoding.GetEncoding(objHttpItems.Encoding);
     }
 }
コード例 #37
0
        /// <summary>
        /// 为请求准备参数
        /// </summary>
        ///<param name="objHttpItems">参数列表</param>
        private void SetRequest(HttpItems objHttpItems)
        {
            #region 处理服务器提交协议错误
            if (objHttpItems.UseUnsafe)
            {
                SetAllowUnsafeHeaderParsing20(objHttpItems.UseUnsafe);
            }
            #endregion

            #region 设置证书
            SetCer(objHttpItems);
            #endregion

            #region 设置Header参数 如果有则添加,如果失败,则重置数据
            if (objHttpItems.Header.Count > 0)
            {
                try
                {
                    request.Headers = objHttpItems.Header;
                }
                catch
                {
                    request.Headers = new WebHeaderCollection();
                }
            }

            if (objHttpItems.AutoRedirectMax)
            {
                request.MaximumAutomaticRedirections = 9999;
            }
            #endregion

            #region 添加 Ajax数据头

            if (objHttpItems.IsAjax)
            {
                request.Headers.Add("x-requested-with: XMLHttpRequest");
            }
            #endregion

            #region 设置代理

            SetProxy(objHttpItems);
            #endregion

            #region 通用属性设置
            //请求方式Get或者Post
            request.Method           = objHttpItems.Method;
            request.Timeout          = objHttpItems.Timeout;
            request.ReadWriteTimeout = objHttpItems.ReadWriteTimeout;
            //Accept
            request.Accept = objHttpItems.Accept;
            //ContentType返回类型
            request.ContentType = objHttpItems.ContentType;
            //UserAgent客户端的访问类型,包括浏览器版本和操作系统信息
            request.UserAgent = objHttpItems.UserAgent;


            // 如果设置编码,则从设置结果读取
            SetEncoding(objHttpItems);
            //设置Cookie
            SetCookie(objHttpItems);
            //来源地址
            request.Referer = objHttpItems.Referer;
            //是否执行跳转功能
            request.AllowAutoRedirect = objHttpItems.Allowautoredirect;
            //设置最大连接
            if (objHttpItems.Connectionlimit > 0)
            {
                request.ServicePoint.ConnectionLimit = objHttpItems.Connectionlimit;
                System.Net.ServicePointManager.DefaultConnectionLimit = objHttpItems.Connectionlimit;
                System.Net.ServicePointManager.SetTcpKeepAlive(true, 5000, 2000); //使用TCP的检测方式  testing
                request.ServicePoint.UseNagleAlgorithm = false;                   //关闭小包优化 testing
                request.AllowWriteStreamBuffering      = false;                   //禁用缓冲
            }
            //设置 post数据在大于1024时是否分包
            request.ServicePoint.Expect100Continue = objHttpItems.Expect100Continue;
            //设置解压缩类型
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.None;
            #endregion

            #region 如果当前为Post则设置并提交数据
            SetPostData(objHttpItems);
            #endregion
        }
コード例 #38
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
        /// <summary>
        /// 设置Cookie
        /// </summary>
        /// <param name="objHttpItems">Http参数</param>
        private void SetCookie(HttpItems objHttpItems)
        {
            //获取当前的cookie

            if (!string.IsNullOrEmpty(objHttpItems.Cookie))
            {
                //Cookie
                request.Headers[HttpRequestHeader.Cookie] = objHttpItems.Cookie;
            }
            //设置Cookie

            if (objHttpItems.CookieCollection != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(objHttpItems.CookieCollection);
            }
            if (objHttpItems.Container != null)
            {
                request.CookieContainer = objHttpItems.Container;
            }
        }
コード例 #39
0
ファイル: Form1.cs プロジェクト: tongwenfei/HttpCodeLib
        private void button6_Click(object sender, EventArgs e)
        {
            CookieContainer cc = new CookieContainer();
            HttpItems items = new HttpItems();
            HttpHelpers helper = new HttpHelpers();
            HttpResults hr = new HttpResults();

            string cookie = "";//字符串方式处理
            items = new HttpItems();
            //items.Container = cc; 自动处理方式
            items.Cookie = cookie;
            items.URL = "http://www.u193.com/opt.php?do=login";
            items.Referer = "http://mrtx.u193.com/";
            items.Method = "Post";
            items.Postdata = "username=ceshiyixia1&password=111111";
            items.Allowautoredirect = true;
            hr = helper.GetHtml(items);

            #region 手动处理字符串Cookie方式
            //hr.Cookie调用时会自动清理cookie 自动剔除无用信息.等同于
            // new XJHTTP().ClearCookie(hr.Cookie);
            cookie = new XJHTTP().UpdateCookie(cookie, hr.Cookie);//手动合并两个Cookie
            #endregion

            #region 自动处理字符串Cookie方式
            //使用ref将cookie传递进方法,每次会自动合并上次与本次返回的cookie
            hr = helper.GetHtml(items, ref cookie);

            #endregion
            //第二次请求
            items = new HttpItems();
            items.URL = "http://mrtx.u193.com/";
            items.Referer = "http://mrtx.u193.com/";
            items.Cookie = cookie;
            //  items.Container = cc; 当cc无法被携带提交失败时使用字符串方式即可
            hr = helper.GetHtml(items);
        }
コード例 #40
0
ファイル: CsdnHelper.cs プロジェクト: yqMac/CSDNHelper
        private string[] regForIn(string proxyip="")
        {
            Start:
            //string proxyip = "";
            int trytimes = 0;
            string[] status = { "操作", "成功/失败", "状态信息", "无验证码", "无附加信息" };
            status[0] = "注册帐号";
            status[1] = "开始";
            status[2] = "";
            status[3] = "";
            status[4] = "";
            Logscomsole(status);

            HttpItems items_reg = new HttpItems();
            HttpHelpers heler_reg = new HttpHelpers();
            HttpResults hr_reg = new HttpResults();

            CookieContainer cc_em = new CookieContainer();
            CookieContainer cc_reg = new CookieContainer();
            Regex regex = null;
            MatchCollection mc = null;

            byte[] regCodebytes = null;

            string email = "";
            string name = "";
            string regCode = "";

            //https://passport.csdn.net/ajax/verifyhandler.ashx//验证码
            hr_reg = heler_reg.GetHtml(new HttpItems()
            {
                URL = @"https://passport.csdn.net/ajax/verifyhandler.ashx",
                ResultType = ResultType.Byte,
                Container = cc_reg
            });

            regCodebytes = hr_reg.ResultByte;

            if (getRegVcode != null)
            {
                regCode = getRegVcode(regCodebytes);
            }
            if (regCode == "")
            {
                status[0] = "注册帐号";
                status[1] = "失败";
                status[2] = "识别验证码失败";
                status[3] = "重试申请";
                status[4] = "";
                Logscomsole(status);
                //reg();
                return regForIn();
            }
            //检查验证码
            //http://passport.csdn.net/account/register?action=validateCode&validateCode=
            items_reg = new HttpItems() {
                URL= "http://passport.csdn.net/account/register?action=validateCode&validateCode=" + regCode,
                Container =cc_reg
            };
            hr_reg = heler_reg.GetHtml(items_reg);
            if (hr_reg.Html.ToLower() != "true")
            {
                status[0] = "注册帐号";
                status[1] = "失败";
                status[2] = "识别验证码失败";
                status[3] = "重试申请";
                status[4] = "";
                Logscomsole(status);
                goto Start;
            }
            trytimes = 0;
            //检查名字
            //http://passport.csdn.net/account/register?action=validateUsername&username=
            //检查邮箱
            //http://passport.csdn.net/account/register?action=validateEmail&[email protected]
            //检查验证码
            //http://passport.csdn.net/account/register?action=validateCode&validateCode=
            //重发激活右键
            //http://passport.csdn.net/account/register?action=resendActiveEmail&username=
            GetMail:

            email = getRegEmail2(cc_em);
            //检查验证码
            //http://passport.csdn.net/account/register?action=validateCode&validateCode=

            hr_reg = heler_reg.GetHtml(new HttpItems() {
                URL = "http://passport.csdn.net/account/register?action=validateEmail&email=" + email,
                Container =cc_reg
            });
            if (hr_reg.Html.ToLower() != "true")
            {
                trytimes++;
                if (trytimes < 5)
                {
                    Logscomsole(new string[] { "注册帐号", "失败", "邮箱验证失败", hr_reg.Html, "" });
                    goto GetMail;
                }
                else
                {
                    Logscomsole(new string[] { "注册帐号","失败", "邮箱验证失败次数过多",hr_reg .Html ,"" });
                    return new string[] { };
                }
            }
            trytimes = 0;
            GetregName:
            name = GetName();
            //检查名字
            hr_reg = heler_reg.GetHtml(new HttpItems()
            {
                URL = "http://passport.csdn.net/account/register?action=validateUsername&username="******"true")
            {
                trytimes++;
                if (trytimes < 5)
                {
                    Logscomsole(new string[] { "注册帐号", "失败", "用户名验证失败", hr_reg.Html, "" });
                    goto GetregName;
                }
                else
                {
                    Logscomsole(new string[] { "注册帐号", "失败", "用户名验证失败次数过多", hr_reg.Html, "" });
                    return new string[] { };
                }
            }
            //string email = string.Format("{0}@qq.com", name);
            string pwd = string.IsNullOrEmpty(mima) ? "aa13655312932bb" : mima;
            Logscomsole(new string[] { "注册帐号", "进行中", "验证成功", "用户名:" + name, "邮箱:" + email });
            PostRequest:

            #region 提交注册请求

            hr_reg = heler_reg.GetHtml(new HttpItems()
            {
                Container = cc_reg,
                URL = "http://passport.csdn.net/account/register?action=saveUser&isFrom=False",
                Postdata = string.Format("fromUrl={0}&userName={1}&email={2}&password={3}&confirmpassword={4}&validateCode={5}&agree=on",
                string.Empty, name, email, pwd, pwd, regCode),
                Method = "POST",

                ProxyIp = proxyip,
            });
            int trycount = 0;
              WaitForEmail:
            trycount++;
            string html = hr_reg.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "");

            if (html.Contains("邮件已发送到邮箱")||html .Contains ("不允许在一分钟内重复发送激活邮件,请稍后"))
            {
                Logscomsole(new string[] {"注册帐号","进行中","激活邮件已发送", "等待邮件到达","" });
                string str = "";
                if (!(str = activeRegEmai2(email, cc_em)).Contains("失败"))
                {
                    str = "http" + str.Substring(5);
                    hr_reg = new HttpHelpers().GetHtml(new HttpItems() {
                        URL =str.Replace ("https","http") ,
                        ProxyIp =proxyip ,
                        //Allowautoredirect =true
                    });

                    hr_reg = new HttpHelpers().GetHtml(new HttpItems()
                    {
                        URL = str.Replace("https", "http"),
                        ProxyIp = proxyip,
                        //Allowautoredirect =true
                    });
                    string htmlss = hr_reg.Html;
                    if (htmlss.Contains("注册成功")||htmlss .Contains ("账户已经激活"))
                    {
                        status[0] = "注册帐号";
                        status[1] = "成功";
                        status[2] = "帐号:" + name;
                        status[3] = "密码:" + pwd;
                        status[4] = "";
                        Logscomsole(status);
                        return new string[] { name, pwd };
                    }
                    else
                    {
                        status[0] = "注册帐号";
                        status[1] = "失败";
                        status[2] = htmlss;
                        status[3] = "";
                        status[4] = "";
                        Logscomsole(status);
                        return new string[] { };
                    }
                }
                else
                {

                     if(trycount <7)
                    {

                        if (trycount % 5 == 0)
                        {
                            status[0] = "注册帐号";
                            status[1] = "进行中";
                            status[2] = "重发邮件" + name;
                            status[3] = "15秒后重新检测";
                            status[4] = "";
                            Logscomsole(status);
                            hr_reg = new HttpHelpers().GetHtml(new HttpItems()
                            {
                                URL = string.Format("http://passport.csdn.net/account/register?action=resendActiveEmail&username={0}", name),
                                ProxyIp =proxyip
                            });
                        }
                        else
                        {
                            status[0] = "注册帐号";
                            status[1] = "进行中";
                            status[2] = "等待激活邮件" + name;
                            status[3] = "15秒后重新检测";
                            status[4] = "";
                            Logscomsole(status);
                        }
                        goto WaitForEmail;
                    }

                    status[0] = "注册帐号";
                    status[1] = "失败";
                    status[2] = "激活邮箱问题";
                    status[3] = str;
                    status[4] = "";
                    Logscomsole(status);
                    if (str.Contains("errorerror"))
                    {
                        return regForIn();
                    }
                    return new string[] { str };
                }
            }
            else
            {
                status[0] = "注册帐号";
                status[1] = "失败";

                if (html.Contains("此ip单位时间内注册个数已超过限定值"))
                {
                    //if (regeristResult != null)
                    //{
                    //    regeristResult();
                    //}
                    status[2] = "此ip单位时间内注册个数已超过限定值";
                    status[3] = "";
                    status[4] = "";
                    Logscomsole(status);
                    return new string[] { "单位时间内注册个数已超过限定值" };
                }
                else
                {
                    status[2] = "验证码错误";
                    status[3] = "重试申请";
                    status[4] = html;
                    Logscomsole(status);
                    goto Start;
                    // return;
                }
            }
            #endregion

            status[0] = "注册帐号";
            status[1] = "失败";
            status[2] = "未知原因";
            status[3] = "";
            status[4] = "";
            Logscomsole(status);

            return new string[] { };
        }
コード例 #41
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 为请求准备参数
 /// </summary>
 ///<param name="objHttpItems">参数列表</param>
 /// <param name="_Encoding">读取数据时的编码方式</param>
 private void SetRequest(HttpItems objHttpItems)
 {
     // 验证证书
     SetCer(objHttpItems);
     //设置Header参数
     if (objHttpItems.Header != null)
     {
         try
         {
             request.Headers = objHttpItems.Header;
         }
         catch
         {
             return;
         }
     }
     if (objHttpItems.IsAjax)
     {
         request.Headers.Add("x-requested-with: XMLHttpRequest");
     }
     // 设置代理
     SetProxy(objHttpItems);
     //请求方式Get或者Post
     request.Method = objHttpItems.Method;
     request.Timeout = objHttpItems.Timeout;
     request.ReadWriteTimeout = objHttpItems.ReadWriteTimeout;
     //Accept
     request.Accept = objHttpItems.Accept;
     //ContentType返回类型
     request.ContentType = objHttpItems.ContentType;
     //UserAgent客户端的访问类型,包括浏览器版本和操作系统信息
     request.UserAgent = objHttpItems.UserAgent;
     // 编码
     SetEncoding(objHttpItems);
     //设置Cookie
     SetCookie(objHttpItems);
     //来源地址
     request.Referer = objHttpItems.Referer;
     //是否执行跳转功能
     request.AllowAutoRedirect = objHttpItems.Allowautoredirect;
     //设置Post数据
     SetPostData(objHttpItems);
     //设置最大连接
     if (objHttpItems.Connectionlimit > 0)
     {
         request.ServicePoint.ConnectionLimit = objHttpItems.Connectionlimit;
     }
 }
コード例 #42
0
ファイル: Form1.cs プロジェクト: tongwenfei/HttpCodeLib
 private void button8_Click(object sender, EventArgs e)
 {
     XJHTTP xj = new XJHTTP();
     item = new HttpItems();
     item.URL = "www.msdn5.com";
     hr = http.GetHtml(item);
     DateTime dt = xj.GetServerTime(hr);  //返回正常格式的时间
     //例如 Date:Sat, 14 Nov 2015 15:55:35 GMT   返回为正常的 2015-11-15 00:21:19 格式
 }
コード例 #43
0
 ///<summary>
 ///采用httpwebrequest方式访问网络,根据传入的URl地址,得到响应的数据字符串。
 ///</summary>
 ///<param name="objHttpItems">参数列表</param>
 ///<returns>HttpResults 为返回结果</returns>
 public HttpResults GetHtml(HttpItems objHttpItems)
 {
     //调用专门读取数据的类
     return(GetHttpRequestData(objHttpItems));
 }
コード例 #44
0
ファイル: HttpCode.cs プロジェクト: lamp525/DotNet
 /// <summary>
 /// 设置证书
 /// </summary>
 /// <param name="objHttpItems"></param>
 private void SetCer(HttpItems objHttpItems)
 {
     if (!string.IsNullOrEmpty(objHttpItems.CerPath))
     {
         //这一句一定要写在创建连接的前面。使用回调的方法进行证书验证。
         ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
         //初始化对像,并设置请求的URL地址
         request = (HttpWebRequest)WebRequest.Create(GetUrl(objHttpItems.URL));
         //创建证书文件
         X509Certificate objx509 = new X509Certificate(objHttpItems.CerPath);
         //添加到请求里
         request.ClientCertificates.Add(objx509);
     }
     else
     {
         //初始化对像,并设置请求的URL地址
         try
         {
             request = (HttpWebRequest)WebRequest.Create(GetUrl(objHttpItems.URL));
         }
         catch
         {
             return;
         }
     }
 }