码迷,mamicode.com
首页 > Windows程序 > 详细

c# WPF 获取网络图片,验证码

时间:2019-01-18 13:58:27      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:box   ams   网络图片   tmp   sage   end   val   ring   origin   

c# WPF 获取网络图片,验证码

  public static BitmapImage getValidCodeBitmap() { 
       
        string url = "http://my.baaaahe.com/Getinterlogin/getVerifyPic?jsonCallBack=?&tmpId=1547785891276";
        BitmapImage b = new BitmapImage();
        try
        {

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.CookieContainer = Common.myCookieContainer;
            request.Referer = "http://my.baaaaihe.com/";
            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
            Common.myCookieContainer.Add(resp.Cookies);
            Stream stream = resp.GetResponseStream();
         

            MemoryStream ms = new MemoryStream();
            const int bufferLen = 4096;
            byte[] buffer = new byte[bufferLen];
            int count = 0;
            while ((count = stream.Read(buffer, 0, bufferLen)) > 0)
            {
                ms.Write(buffer, 0, count);
            }
            ms.Seek(0, SeekOrigin.Begin);
            stream.CopyTo(ms);
            b.BeginInit();
            b.StreamSource = ms;
            b.EndInit();
        }

        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);

        }
        return b;

        
        }

  

c# WPF 获取网络图片,验证码

标签:box   ams   网络图片   tmp   sage   end   val   ring   origin   

原文地址:https://www.cnblogs.com/wgscd/p/10287216.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!