2012-08-16 2 views
0

JSESSIONID 쿠키를 사용하는 사이트와 상호 작용하는 ASP.Net 응용 프로그램을 작성합니다. 각 요청마다 쿠키를 반환하라는 내용이 나와 있습니다. 로그인 응답의 헤더에서 쿠키를 추출합니다. 그러나 다음 요청에서이를 사용하려고하면 'PlatformNotSupported error'가 발생합니다. 분명히 보안의 '개선'때문입니다. 블로그에서 Proxy Server를 작성하고 IHttpModule에서 파생 된 클래스를 작성하는 방법을 살펴 보았습니다. 혼란 스럽습니다. 쿠키를 전송할 수 있도록 HttpWebRequest를 코딩하는 간단한 방법이 있습니까?Asp.Net HTTPWebRequest JSESSIONID 쿠키 반환

가끔씩 StackOverflow를 사용하는 사용자가 댓글을 게시하려했으나 게시를 수정하지 못했습니다. 코드 : 문자열 쿠키 = "JSESSIONID ="+ 세션 [ "SessionId"]. ToString();

 if(Request.Cookies["JSESSIONID"]==null) 
     { 

      //Request.Headers.Add("Cookie",cookie);//PlatformNotSupportedError 
      HttpCookie cook = new HttpCookie("JSESSIONID", Session["SessionId"].ToString()); 
      Request.Cookies.Add(cook); 


     } //The prev login response had the cookie in the header not in the cookies collection so I was trying to send back the same way. ASP.net app at this stage. Will be service after get it going. Thx Bob 
+0

Bob 게시 할 수있는 코드 샘플이 있습니까? 우연히 웹 서비스를 통해이 작업을하려고합니까? – MethodMan

답변

1

발견. 쿠키 컬렉션을 만들어서 원래 로그인 요청에 할당해야합니다.
쿠키가 반환 될 때 SessionId 쿠키가 컬렉션에 나타납니다.

byte[] bytes = Encoding.UTF8.GetBytes(xml); 
    CookieContainer cookies = new CookieContainer(); 
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
    request.CookieContainer = cookies; 
    request.Credentials = new NetworkCredential(user, password); 
    request.Method = "POST"; 
    request.ContentLength = bytes.Length; 
    request.ContentType = "text/xml"; 
    using (Stream requestStream = request.GetRequestStream()) 
    { 
    requestStream.Write(bytes, 0, bytes.Length); 
    }