473,479 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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();
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;
}
}
}
}

Jul 21 '05 #1
0 1716

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5729
by: Tom Jones | last post by:
Hi, I place an http request to a web server using HttpWebRequest. When the response comes back (via a HttpWebResponse) the Cookies collection in the response is empty, though if I scan through...
1
4187
by: Ravi | last post by:
Hi , i am trying to pass the same session Id to all the webrequest, but sometimes the response.cookies returns zero and sometimes one. is this to do something with cookies expire. In this sample...
3
1824
by: Thaynann | last post by:
I ham tryin to access a website, the first time i send a GET to display the first page it displays the HTML code, but always with text "Enable Cookies In Your Browser", is there a way to have it...
3
1081
by: Ulrich Sprick | last post by:
Hi all, I am beginnig to try out the exciting Web stuff in .NET, so please forgive my perhaps silly question. I am trying to communicate with a Web server using HttpWebRequest and -Response...
1
1782
by: Prasanna Padmanabhan | last post by:
I am writing a simple HTTP Client in .NET. I make an HTTP Request and examine the response. I get an empty CookieCollection when I do HttpWebResponse.Cookies. However HttpWebResponse.Headers...
16
11012
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
0
321
by: Michael Evanchik | last post by:
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...
2
3380
by: Mr Flibble | last post by:
Hey! I get a 404 from a website (this is "correct behaviour") and I'm interested in the value in the cookie "SMSESSION". The question is the following code generates an exception due to the...
2
9662
by: GHS | last post by:
I have some code to connect to a website and pull some content out of the HTML. I've verified that the 2 URLs I'm using are perfectly fine in Internet Explorer and both of them return results...
0
7027
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7067
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6719
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4463
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.