public partial class Illegal : Controller
{
public FileContentResult CreateVcode(string url = "http://www.gdhzcgs.com/cgs/captcha.jpg", string sessionidURL = null)
{
if (sessionidURL != null) try { Session["sessionId"] = ((HttpWebRequest)WebRequest.Create(sessionidURL)).GetResponse().Headers["Set-Cookie"].ToString(); } catch { return null; }
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
if (!string.IsNullOrEmpty(sessionidURL)) wr.Headers.Add("Cookie", Session["sessionId"].ToString());
try
{
using (WebResponse ws = wr.GetResponse())
{
using (Stream rd = ws.GetResponseStream())
{
Bitmap image = new Bitmap(rd);
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Jpeg);
if (!string.IsNullOrEmpty(sessionidURL)) Session["sessionId"] = ws.Headers["Set-Cookie"].ToString();
return File(stream.ToArray(), @"image/jpeg");
}
}
}
catch { return null; }
}
}
.net MVC 跨域获取验证码
最新推荐文章于 2023-10-17 14:43:46 发布