标签: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; }
标签:box ams 网络图片 tmp sage end val ring origin
原文地址:https://www.cnblogs.com/wgscd/p/10287216.html