Cookies not sending in HttpWebRequest

G

Guest

Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to using VB6
and the inet control!!!

If you notice in my class below, i was commenting out different codes that i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the domains where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!

my command button
---------------------------
ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedomain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&loginId=apientry&password=highview&rememberMe=off","");

ret=htp.httpit("http://my.screenname.aol.com/_cqr/l...%26&isSiteStateEncoded=true&lang=en&locale=us","","");


my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;

namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;

public http()
{
//
// TODO: Add constructor logic here
//
}


public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}

if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}

HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}


HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}


class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}
 
L

Landi

First of all I contact AOL and make sure it's ok for you to be doing this. I
would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

Michael Evanchik said:
Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to using VB6
and the inet control!!!

If you notice in my class below, i was commenting out different codes that i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the domains where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!

my command button
---------------------------
ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedom
ain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=O
rigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%2
53Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&log
inId=apientry&password=highview&rememberMe=off","");ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=co
pyCookies&siteId=alertsFEmain&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%2
52Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteSta
teEncoded=true&lang=en&locale=us","","");


my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;

namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;

public http()
{
//
// TODO: Add constructor logic here
//
}


public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}

if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}

HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}


HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}


class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}
 
G

Guest

Landi, what in the world are you talking about. Im loggin in alerts.aol.com
to automate alerts for myself. I do not need their permission to do what i
can using a regular internet browswer. You do not need to use AOL as in
example. Going to any website using cookies it would not work.

Thank for no help

Mike

Landi said:
First of all I contact AOL and make sure it's ok for you to be doing this. I
would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

Michael Evanchik said:
Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to using VB6
and the inet control!!!

If you notice in my class below, i was commenting out different codes that i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the domains where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!

my command button
---------------------------
ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedom
ain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=O
rigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%2
53Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&log
inId=apientry&password=highview&rememberMe=off","");ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=co
pyCookies&siteId=alertsFEmain&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%2
52Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteSta
teEncoded=true&lang=en&locale=us","","");


my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;

namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;

public http()
{
//
// TODO: Add constructor logic here
//
}


public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}

if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}

HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}


HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}


class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}
 
L

Landi

All I meant to say was for you to check up with AOL before you do that.
Sorry for giving you the heads up. And, above all, sorry for trying to help
you out.

By the way, do you know that you just gave out your username and password to
the world?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

Michael Evanchik said:
Landi, what in the world are you talking about. Im loggin in alerts.aol.com
to automate alerts for myself. I do not need their permission to do what i
can using a regular internet browswer. You do not need to use AOL as in
example. Going to any website using cookies it would not work.

Thank for no help

Mike

Landi said:
First of all I contact AOL and make sure it's ok for you to be doing this. I
would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

Michael Evanchik said:
Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example.
But
for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to
using
VB6
and the inet control!!!

If you notice in my class below, i was commenting out different codes
that
i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the
domains
where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!

my command button
ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedom
ain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=O
rigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%2
53Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&log
inId=apientry&password=highview&rememberMe=off",""); ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=co
pyCookies&siteId=alertsFEmain&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%2
52Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteSta
teEncoded=true&lang=en&locale=us","","");
my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;

namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;

public http()
{
//
// TODO: Add constructor logic here
//
}


public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}

if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}

HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}


HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}


class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}
 
G

Guest

yes i do know, aim accounts are free, i created on just for this test. The
username and password is meaningless to me. I do not have to check with aol,
to login to their service, that was a weird statement you made

Landi said:
All I meant to say was for you to check up with AOL before you do that.
Sorry for giving you the heads up. And, above all, sorry for trying to help
you out.

By the way, do you know that you just gave out your username and password to
the world?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

Michael Evanchik said:
Landi, what in the world are you talking about. Im loggin in alerts.aol.com
to automate alerts for myself. I do not need their permission to do what i
can using a regular internet browswer. You do not need to use AOL as in
example. Going to any website using cookies it would not work.

Thank for no help

Mike

Landi said:
First of all I contact AOL and make sure it's ok for you to be doing this. I
would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

message Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But
for
some reason, im packet sniffing with ethreal and cookies are not being
sent
along with the header and post data. here is the code im using. Can
anyone
please tell me why this is happening? I do not want to go back to using
VB6
and the inet control!!!

If you notice in my class below, i was commenting out different codes that
i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i
loaded
them?) Either way, the only difference in the domain below is one is a
https
and the other is a http. I have even used an example where the domains
where
exactly the same, and still packet sniffing i would see no cookies beeing
sent with this object. Can anyone help. Thank you in advance!

my command button
---------------------------

ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedom
ain=alertsFEmain&siteId=alertsFEmain&lang=en&locale=us&authLev=1&siteState=O
rigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%2
53Ff%253D1%2526&isSiteStateEncoded=true&mcState=initialized&usrd=1870944&log
inId=apientry&password=highview&rememberMe=off","");


ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=co
pyCookies&siteId=alertsFEmain&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%2
52Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteSta
teEncoded=true&lang=en&locale=us","","");


my class
----------
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.IO;
using System.Text;

namespace backupbatch
{
/// <summary>
/// Summary description for http.
/// </summary>
public class http
{
ManualResetEvent wait = new ManualResetEvent(false);
CookieContainer CookieJar = new CookieContainer();
CookieCollection CookieCol = new CookieCollection();
HttpWebResponse HttpWResponse;
Uri lasturl;
string retrn = "";
int ret;

public http()
{
//
// TODO: Add constructor logic here
//
}


public string httpit(string url, string poststr, string proxy)
{
if (url.IndexOf("https") > 1)
{
ServicePointManager.CertificatePolicy = new CertPolicy();
}

if (proxy.Length > 0)
{
WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);
GlobalProxySelection.Select = proxyObject;
}

HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.CookieContainer = CookieJar;
//if (retrn.Length > 0)
//{
// HttpWRequest.CookieContainer.Add(lasturl, CookieCol);
//}
//lasturl = new Uri("https://my.screenname.aol.com");
HttpWRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWRequest.UserAgent = "your mother";
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Timeout = 300000;
if(poststr.Length > 0 )
{
HttpWRequest.Method = "POST";
HttpWRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToString());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();
}
else
{
HttpWRequest.Method = "GET";
}


HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
Encoding.ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn + "\n\n"+s;
return retrn;
}


class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}
 
J

Joerg Jooss

Michael said:
Hello all, since i wanted to use ssl and its seems easy to do so with
this object. Im trying to login to a webserver (aol) for this
example. But for some reason, im packet sniffing with ethreal and
cookies are not being sent along with the header and post data. here
is the code im using. Can anyone please tell me why this is
happening? I do not want to go back to using VB6 and the inet
control!!!

If you notice in my class below, i was commenting out different codes
that i was trying. I was getting some hint from google since im
accessing a different domain name that the cookies would not work
(even though i loaded them?) Either way, the only difference in the
domain below is one is a https and the other is a http. I have even
used an example where the domains where exactly the same, and still
packet sniffing i would see no cookies beeing sent with this object.
Can anyone help. Thank you in advance!

Some thoughts:

1. Set a real User-Agent header. How do you expect
HttpWRequest.UserAgent = "your mother" to be dealt with in any somewhat
secure web infrastructure?

2. Don't fool around with the CookieContainer. Create an instance,
associate it with each request you send, and that's it. There's no
reason to reassign it or copy stuff around between the container and
the cookie collection in the response.

3.I'd be surprised if
HttpWRequest.Credentials = CredentialCache.DefaultCredentials
gets you authenticated with AOL...

4. Are you sure you're sending all parameters the AOL web site expects
to receive? Make sure you didn't overlook some hidden functionality
embedded in JavaScript or some hidden field you need to post as well.

Cheers,
 
G

Guest

Thanks for your response.

1) the agent does not matter

2) ill give that a try

3) actualy it does without a problem.

4) that is a quite possibility. But again, dont even use this example with
aol. Any website. No cookies are being sent. nothing. Even though in the
debugger i see them recieved and set before my next send.
 
J

Joerg Jooss

Michael said:
Thanks for your response.

1) the agent does not matter

OK, if you checked ;-)
2) ill give that a try

3) actualy it does without a problem.

I'm sure it doesn't, as AOL won't likely use your workstation's
credentials, and hopefully doesn't employ Basic authentication. This
line doesn't affect the resulting HTTP request in any way.
4) that is a quite possibility. But again, dont even use this
example with aol. Any website. No cookies are being sent. nothing.
Even though in the debugger i see them recieved and set before my
next send.

I've been playing around with both .NET 1.1 and 2.0 for half an hour
now and don't have any problems sending or receiving cookies. BTW, when
you say "No cookies are being sent", do you mean sent along with the
request or with the response?

Cheers,
 
J

Joerg Jooss

Michael said:
can you show me your code or is that top secret.

i posted mine

Here we go:

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Networking
{
public class SimpleUserAgent
{
private CookieContainer cookieContainer = new CookieContainer();
private static readonly string userAgent =
"Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.7.8) " +
"Gecko/20050511 Firefox/1.0.4";
private static readonly string testPage =
"http://www.google.com";

public SimpleUserAgent()
{
}

public void Get(string uri)
{
Get(new Uri(uri));
}

public void Get(Uri uri)
{
HttpWebRequest request = CreateRequest(uri); ;
using (HttpWebResponse response =
(HttpWebResponse) request.GetResponse())
using (Stream responseStream =
response.GetResponseStream())
{
MemoryStream memoryStream = new MemoryStream(0x10000);
byte[] buffer = new byte[0x1000];
int bytes;
while ((bytes = responseStream.Read(
buffer, 0, buffer.Length)) > 0)
{
memoryStream.Write(buffer, 0, bytes);
}
ShowCookies(this.cookieContainer.GetCookies(uri));
}
}

private HttpWebRequest CreateRequest(Uri uri)
{
HttpWebRequest request =
(HttpWebRequest) WebRequest.Create(uri);
request.Proxy = WebProxy.GetDefaultProxy();
request.UserAgent = userAgent;
return request;
}

private void ShowCookies(CookieCollection cookies)
{
int i = 1;
foreach (Cookie cookie in cookies)
{
Console.WriteLine("Cookie #{0}: {1} ({2})",
i, cookie, cookie.Path);
i++;
}
Console.WriteLine("***");
}

public static void Main(string[] args)
{
SimpleUserAgent agent = new SimpleUserAgent();
agent.Get(testPage);
agent.Get(testPage);
Console.Read();
}
}
}

Note that I chose Google as test page, but any old web site that sets a
cookie will do.

You should hook up a debugging proxy as system proxy in between. The
code will pick it up and use it.

Cheers,
 
Top