2013-07-22 1 views
0

나는 이미지를 파일에 저장하지 않고 web.poni에서 직접 브라우저에 저장하고 싶습니다. 아래 코드를 사용하여 브라우저에 직접 표시하고 싶습니다. 웹 사이트에서 원하는 웹 응답을 captcha 이미지로 제공합니다. display.please 도와주세요.asp.net의 httpwebresponse 스트림에서 직접 이미지를 표시하는 방법은 무엇입니까?

public void captcha(string id, string pass) 
{ 
    HttpWebRequest req; 
    HttpWebResponse response; 
    string strNewValue,ckuser,ckpass; 
    System.Drawing.Image returnval; 
    ckuser = id; 
    ckpass = pass; 
    this.req = (HttpWebRequest)WebRequest.Create("http://site2sms.com/security/captcha.asp"); 
    ServicePointManager.Expect100Continue = false; 
    this.req.CookieContainer = new CookieContainer(); 
    this.req.AllowAutoRedirect = false; 
    this.req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0"; 
    this.req.Accept = "*/*"; 
    this.req.Method = "POST"; 
    this.req.CookieContainer = cookieCntr; 
    this.req.ContentType = "application/x-www-form-urlencoded"; 
    this.req.Referer = "http://site2sms.com/verification.asp?source=login"; 
    this.strNewValue = "user=" + ckuser + "&password=" + ckpass + "&Submit=Sign+in"; 
    this.req.ContentLength = this.strNewValue.Length; 
    StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII); 
    writer.Write(this.strNewValue); 
    writer.Close(); 
    this.response = (HttpWebResponse)this.req.GetResponse(); 
    returnval = Image.FromStream(response.GetResponseStream()); 
    // returnval.Save(Server.MapPath("captcha.bmp")); 
    Response.AppendHeader("Content-Disposition:", "inline;filename=captcha.bmp"); 
    Response.ContentType = "image/bmp"; 
    Response.Write(returnval); 
    Response.End(); 
    this.response.Close(); 
} 
+0

코드에 무엇이 잘못된지 또는 어떤 오류가 발생했는지 자세히 지정하십시오. –

+0

이미지 저장 경로 권한을 확인하십시오. –

답변

1
  • 직접 클라이언트로 스트림을 보내 HttpResponse.WriteFile 방법을 사용할 수 있습니다. 지정한 파일을 HTTP 응답 출력 스트림에 직접 씁니다.

  • IHttpHandler를 만들어 스트림을 보내면 일부 페이지 수명주기를 피하고 성능을 높일 수 있습니다. Here is the link

관련 문제