473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Can not get cookies from a web page.

Hi all,
I am making a http request to a html page residing on a server through
a desktop application .
The page is actually an html page with some perl queries on the top.
For this page I have some cookies set on my local browser.
The content of the page is dependent on the cookie value
My problem is that when I make the request through a browser, I am
getting the right contents, but when I make request through my desktop
application the contents are same as required.
Is there any way to make the http request via the browser or anyway to
retrieve the cookies.
Please help me out.

Thanks in advance

Apr 12 '07 #1
3 2331
Shashank,

What you have to do is read the cookie collection from where the browser
keeps the cookies. For IE, you can call the WinInet library functions
through the P/Invoke layer. For other browsers, you will have to make a
call dependent on the browser architecture.

Once you have that, you can use the CookieContainer request on the
HttpWebRequest class to associate cookies with the request you are making.

You will probably want to make sure you set the UserAgent property as
well, just so the service thinks you are coming through a browser (it might
make some decisions on what to send back based on that, but without knowing
what the service does or who controls it, it is impossible to say).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Shashank" <sh***************@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro ups.com...
Hi all,
I am making a http request to a html page residing on a server through
a desktop application .
The page is actually an html page with some perl queries on the top.
For this page I have some cookies set on my local browser.
The content of the page is dependent on the cookie value
My problem is that when I make the request through a browser, I am
getting the right contents, but when I make request through my desktop
application the contents are same as required.
Is there any way to make the http request via the browser or anyway to
retrieve the cookies.
Please help me out.

Thanks in advance

Apr 12 '07 #2
Here's a short example of using the CookieContainer:
private CookieContainer m_CookieContainer = null;
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://yoursite.com/yourpage.aspx");
request.CookieContainer = this.m_CookieContainer;
request.Timeout = TimeOutTime;
request.UserAgent = "whateveryouwanthere";
request.Accept = "text/html";
request.Referer = "whatever httpreferer if necessary"
request.KeepAlive = true;
request.MediaType = "text/html;";

HttpWebResponse w = null;
w = (HttpWebResponse) request.GetResponse();

//..etc

--Peter

"Shashank" <sh***************@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro ups.com...
Hi all,
I am making a http request to a html page residing on a server through
a desktop application .
The page is actually an html page with some perl queries on the top.
For this page I have some cookies set on my local browser.
The content of the page is dependent on the cookie value
My problem is that when I make the request through a browser, I am
getting the right contents, but when I make request through my desktop
application the contents are same as required.
Is there any way to make the http request via the browser or anyway to
retrieve the cookies.
Please help me out.

Thanks in advance

Apr 12 '07 #3
I used the CookieContainer class but even this is not working..

On Apr 13, 1:20 am, "Peter Bromberg [C# MVP]"
<petebromb...@yahoo.nospammin.comwrote:
Here's a short example of using the CookieContainer:

private CookieContainer m_CookieContainer = null;
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://yoursite.com/yourpage.aspx");
request.CookieContainer = this.m_CookieContainer;
request.Timeout = TimeOutTime;
request.UserAgent = "whateveryouwanthere";
request.Accept = "text/html";
request.Referer = "whatever httpreferer if necessary"
request.KeepAlive = true;
request.MediaType = "text/html;";

HttpWebResponse w = null;
w = (HttpWebResponse) request.GetResponse();

//..etc

--Peter

"Shashank" <shashank.pande...@gmail.comwrote in message

news:11**********************@y5g2000hsa.googlegro ups.com...
Hi all,
I am making a http request to a html page residing on a server through
a desktop application .
The page is actually an html page with some perl queries on the top.
For this page I have some cookies set on my local browser.
The content of the page is dependent on the cookie value
My problem is that when I make the request through a browser, I am
getting the right contents, but when I make request through my desktop
application the contents are same as required.
Is there any way to make the http request via the browser or anyway to
retrieve the cookies.
Please help me out.
Thanks in advance

Apr 16 '07 #4

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

Similar topics

5
by: TG | last post by:
This is more of a pain than I thought it would be. I need a simple code segment to determine whether a browser accepts cookies or not. When I pass variables between pages when cookies are turned...
4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
9
by: | last post by:
Is it possible for a user to enable permanent cookies but disable session cookies.....this seems like a contradition yet this is what I appear to be reading in online articles?
3
by: Marcin Gorzynski | last post by:
Hi Our partner is using our page in a frame. That couses a problem because our domain is unable to issue the cookie also session does not work. each time you click in the frame new session is...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
8
by: CDARS | last post by:
Hi all, I have a confusing question on ASP.NET cookies usage: 1> Response.Cookies("test").value = Now 2> Response.Write(Request.Cookies("test").value) 3> 4> Response.write("<hr>") 5>...
5
by: Miljana | last post by:
Hi, I have one problem with cookies in ASP.NET application. It seems that I can not retreive cookie from Request.Cookies collection. I put cookie in Response.Cookies collection, and after page...
6
by: Pete Davis | last post by:
I've never done anything with cookies. What I'm trying to do is very straight-forward, but for some reason, it just doesn't seem to want to work. I have a helper class with some static methods. Two...
3
by: Phillip N Rounds | last post by:
I'm having trouble with using cookies to monitor the stages of login. I have a two stage Registration page ( register.aspx ) and my target page ( MyPage.aspx ) I'm using a cookie named LoginStatus...
5
by: Kevin Blount | last post by:
I've setup a method (C#) that I can call, passing it a cookie name, then a name-value pair. The idea is that as I can't append to a cookie, I read the cookie value, append by name=pair to the end...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.