로그인 프로그램에 문제가 있습니다. 한 번 로그인 한 다음 CookieContainer 및 CookieCollection (http 클래스와 함께)을 로그인 한 다음 다시 로그인하려고하면 첫 번째 요청의 쿠키가 계속 제출됩니다. 왜 쿠키가 주위에 붙어 있습니까?C# HttpWebRequest CookieContainer/Object 인스턴스간에 지속되는 컬렉션?
예 :
HTTP uh;
MainWindow()
{
uh = new HTTP();
uh.login("mySite");
//Logging in....
//Login Successful.....
uh.cookieContainer = null;
uh.cookieCollection = null;
uh = null;
uh = new HTTP();
uh.loging("mySite");
//Logging in, with cookies from first login
//Login Fails.....
}
편집 : HTTP 클래스의 거친 표현 ...
public class HTTP()
{
public CookieContainer cookieContainer;
public CookieCollection cookieCollection;
private HttpWebRequest Request;
private HttpWebResponse Response;
public HTTP()
{
this.cookieContainer = new CookieContainer();
this.cookieCollection = new CookieCollection();
}
public HttpWebResponse login(string url)
{
string[] cred = new string[2] { "un", "pw" };
this.Request = (HttpWebRequest)HttpWebRequest.Create(url);
this.Request.CookieContainer = cookieContainer;
byte[] ByteArray = Encoding.UTF8.GetBytes(String.Format("un={0}&pw={1}", cred));
this.Request.ContentLength = ByteArray.Length;
Stream DataStream = this.Request.GetRequestStream();
DataStream.Write(ByteArray, 0, ByteArray.Length);
DataStream.Close();
Response = (HttpWebResponse)this.Request.GetResponse();
this.cookieCollection = Response.Cookies;
return Response;
}
public bool responseHandle(HttpWebResponse r)
{
//Determines success, logs headers, html body, etc..
}
}
편집 | 해결책 : 위의 코드는 아무런 문제가 없습니다. 나는 내 로그 아웃 버튼에 HTTP
null/new 코드를 넣지 않는 바보 같은 실수를했다. 그래서 결코 재계약을하지 못했습니다. 죄송합니다 everyones 시간을 낭비합니다.
당신은 판단을 내리기 위해'HTTP' 클래스의 구현을 제공해야합니다. – BrokenGlass
개략 설명을 추가했습니다. – PiZzL3
공유 해 주셔서 감사합니다. 제게 많은 도움이되었습니다. – LikePod