Exemplo n.º 1
0
        public bool GetImage(ClassHttpPost webPost, string strFile, out string strError, string strUrl, string strReffer)
        {
            strError = "";
            try
            {
                Stream stream = webPost.GetHttpPageSteam(strUrl, "gb2312", "get", "", "", strReffer, "*/*", "");
                if (stream == null)
                {
                    strError = "获取验证码失败,网络错误";
                    return false;
                }

                List<byte> list = new List<byte>();
                while (true)
                {
                    int data = stream.ReadByte();
                    if (data == -1)
                        break;
                    list.Add((byte)data);
                }
                byte[] bytes = list.ToArray();
                if (File.Exists(strFile))
                {
                    File.Delete(strFile);
                }
                FileStream fs = new FileStream(strFile, FileMode.Create);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(bytes);
                bw.Close();
                fs.Close();
                return true;
            }
            catch
            {
                strError = "获取验证码失败,获取异常";
                return false;
            }
        }
Exemplo n.º 2
0
        private bool GetImage(ClassHttpPost m_webPost,string strFile)
        {
            try
            {
                string strUrl = string.Format("http://passport.kedou.com/checkCode.htm?checkCode2=checkCode2&{0}", DateTime.Now.ToString("yyyyMMddHHmmss"));
                Stream stream = m_webPost.GetHttpPageSteam(strUrl, "gb2312", "get", "", "", "http://passport.kedou.com/front/noLogin/goRegist2_front.htm?userType=1&returnCode=quick&site_id=1024_gameclient&return_url=http://www.kedou.com", "*/*", "");
                if (stream == null)
                {
                    return false;
                }

                List<byte> list = new List<byte>();
                while (true)
                {
                    int data = stream.ReadByte();
                    if (data == -1)
                        break;
                    list.Add((byte)data);
                }
                byte[] bytes = list.ToArray();
                if (File.Exists(strFile))
                {
                    File.Delete(strFile);
                }
                FileStream fs = new FileStream(strFile, FileMode.Create);
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(bytes);
                bw.Close();
                fs.Close();
                return true;
            }
            catch (System.Exception ex)
            {

            }
            return false;
        }