471,338 Members | 896 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

HttpWebResponse not sending cookies!

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=alertsF Emain&lang=en&locale=us&authLev=1&siteState=OrigUr l%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fs hared%252Fnoauth.ev%253Ff%253D1%2526&isSiteStateEn coded=true&mcState=initialized&usrd=1870944&loginI d=apientry&password=highview&rememberMe=off","");

ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=copyCookies&siteId=alertsFEmain& authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%252Fa lerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253F f%253D1%2526&isSiteStateEncoded=true&lang=en&local e=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.ToStri ng());
HttpWRequest.ContentLength = PostData.Length;
Stream tempStream = HttpWRequest.GetRequestStream();
HttpWRequest.Method = "GET";
HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse.Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
//CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
string s = sr.ReadToEnd();
retrn = retrn + "\n\n"+s;
return retrn;
class CertPolicy: ICertificatePolicy
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
WebRequest request, int certificateProblem)
return true;

Jul 21 '05 #1
0 1576

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Tom Jones | last post: by
3 posts views Thread by Thaynann | last post: by
1 post views Thread by Prasanna Padmanabhan | last post: by
16 posts views Thread by Cheung, Jeffrey Jing-Yen | last post: by
reply views Thread by Michael Evanchik | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.