tags:

views:

905

answers:

1

Ok, if I have this right, my code can get cookies at a specific url, but then once I get the cookie, into the container, how can I send it to the client via socket? Like the code directly below does here for regular http-page requests.

byte[] buffer = new byte[bz];
rebu = responsestream.Read(buffer, 0, bz);
while (rebu != 0)
{
    soket.Send(buffer, rebu, 0);
    rebu = responsestream.Read(buffer, 0, bz);
}

My code section for requests/responses

System.Net.Configuration.HttpWebRequestElement wr = new System.Net.Configuration.HttpWebRequestElement();
wr.UseUnsafeHeaderParsing = true;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.CookieContainer.Add(cookieContainer.GetCookies((Uri)url));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responsestream = response.GetResponseStream();
byte[] buffer = new byte[bz];
rebu = responsestream.Read(buffer, 0, bz);
while (rebu != 0)
{
    soket.Send(buffer, rebu, 0);
    rebu = responsestream.Read(buffer, 0, bz);
}

This is part of a proxy server I'm coding and I'm having trouble with cookies.

C#.net3.5

+1  A: 

The cookies in the HttpRequest.CookieContainer goes to the destination URL specified in the request via the HTTP Cookie: header. Normally, a proxy doesn't set its own cookies. You should check any incoming cookies from the client to pass on but you don't need to do anything special if the server sets its own cookies for the client--it will be automatically part of the response stream as a HTTP Set-Cookie: header.

Mark Cidade