I am coding a http proxy in c# and using httpwebrequest class to send request to the web server, when the server returns multiple set-cookie headers then the httpwebresponse object combines them all in to a single set-cookie key-value pair.
I am tryin to get the value of the headers in the following way. -
-
for (int i = 0; i < response.Headers.Count; ++i)
-
Console.WriteLine("{0}:{1}", response.Headers.Keys[i], response.Headers[i]);
-
-
when i send a request to mypsace.com the server returns the following :
set-cookie headers
Set-Cookie: MYUSERINFO=; domain=.myspace .com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/
Set-Cookie: MYUSERINFO=; domain=myspace. com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/
Set-Cookie: USER=; domain=.myspace .com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/
Set-Cookie: USER=; domain=myspace. com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/
when i try to get the same through my code it looks like this :
Set-Cookie:MYUSERIN FO=; domain=.myspace .com; expires=Wed, 19-Jan-2005 08:28:17 G
MT; path=/,MYUSERINFO=; domain=myspace. com; expires=Wed, 19-Jan-2005 08:28:17 GM
T; path=/,USER=; domain=.myspace .com; expires=Wed, 19-Jan-2005 08:28:17 GMT; pat
h=/,USER=; domain=myspace. com; expires=Wed, 19-Jan-2005 08:28:17 GMT
I tried using the response.cookie s method but gave up on it as it was processing all the cookie values, i need to get the exact values of the raw headers to proxy it to the browser.
Any help would be much appreciated, this is my first project in .net and i think i hav hit a road block here.
thanks in advance
5 10854 Plater 7,872
Recognized Expert Expert
Why not just use the .Cookies property to see what cookies are trying to be set and the combine from there?
Why not just use the .Cookies property to see what cookies are trying to be set and the combine from there?
hi plater, thanks for the reply.
i did think about it as well, it would involve more code and i might possible miss out something.i have seen websites setting really weird cookies.i was hoping if there was a more direct way through which i could directly access the raw set-cookie headers, that way possibilities of introducing bugs would become less.
Plater 7,872
Recognized Expert Expert
Well I didn't see how the two headers you showed were different?
I would guess that the extra line breaks are just because you are using Console, which will insert them to line-wrap as needed.
EDIT: seems it doesn't make any entries in the Cookies section, weird.
Here's what I got from myspace.com -
Content-Length: 51280
-
Cache-Control: private
-
Content-Type: text/html; charset=utf-8
-
Set-Cookie: MYUSERINFO=; domain=.myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,MYUSERINFO=; domain=myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,USER=; domain=.myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,USER=; domain=myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,MSCulture=IP=74.92.34.25&IPCulture=en-US&PreferredCulture=en-US&PreferredCulturePending=&Country=US&ForcedExpiration=0&timeZone=0&USRLOC=QXJlYUNvZGU9NjAzJkNpdHk9QnJvb2tsaW5lJkNvdW50cnlDb2RlPVVTJkNvdW50cnlOYW1lPVVuaXRlZCBTdGF0ZXMmRG1hQ29kZT01MDYmTGF0aXR1ZGU9NDIuNzQ5NCZMb25naXR1ZGU9LTcxLjY2ODEmUG9zdGFsQ29kZT0wMzAzMyZSZWdpb25OYW1lPU5I; domain=.myspace.com; expires=Fri, 08-Feb-2008 16:42:19 GMT; path=/,SessionDDF1=42cd8b692c61f9128296c4dc372a5e9655c15692e06749df; domain=.myspace.com; path=/,SessionDDF2=16e5eae9c9f477affed68ed69aa6e7414885361be2a4277b; domain=.myspace.com; path=/; expires=Friday, 01-Aug-08 16:42:19 GMT
-
Server: Microsoft-IIS/6.0
-
X-AspNet-Version: 2.0.50727
-
X-Server: 66dc745d1825fe9ae98e6af186c04a019bd5bfcab67cbd10
-
Date: Fri, 01 Feb 2008 16:42:19 GMT
-
Well I didn't see how the two headers you showed were different?
I would guess that the extra line breaks are just because you are using Console, which will insert them to line-wrap as needed.
EDIT: seems it doesn't make any entries in the Cookies section, weird.
Here's what I got from myspace.com -
Content-Length: 51280
-
Cache-Control: private
-
Content-Type: text/html; charset=utf-8
-
Set-Cookie: MYUSERINFO=; domain=.myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,MYUSERINFO=; domain=myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,USER=; domain=.myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,USER=; domain=myspace.com; expires=Wed, 19-Jan-2005 08:28:17 GMT; path=/,MSCulture=IP=74.92.34.25&IPCulture=en-US&PreferredCulture=en-US&PreferredCulturePending=&Country=US&ForcedExpiration=0&timeZone=0&USRLOC=QXJlYUNvZGU9NjAzJkNpdHk9QnJvb2tsaW5lJkNvdW50cnlDb2RlPVVTJkNvdW50cnlOYW1lPVVuaXRlZCBTdGF0ZXMmRG1hQ29kZT01MDYmTGF0aXR1ZGU9NDIuNzQ5NCZMb25naXR1ZGU9LTcxLjY2ODEmUG9zdGFsQ29kZT0wMzAzMyZSZWdpb25OYW1lPU5I; domain=.myspace.com; expires=Fri, 08-Feb-2008 16:42:19 GMT; path=/,SessionDDF1=42cd8b692c61f9128296c4dc372a5e9655c15692e06749df; domain=.myspace.com; path=/,SessionDDF2=16e5eae9c9f477affed68ed69aa6e7414885361be2a4277b; domain=.myspace.com; path=/; expires=Friday, 01-Aug-08 16:42:19 GMT
-
Server: Microsoft-IIS/6.0
-
X-AspNet-Version: 2.0.50727
-
X-Server: 66dc745d1825fe9ae98e6af186c04a019bd5bfcab67cbd10
-
Date: Fri, 01 Feb 2008 16:42:19 GMT
-
well actually the mypsace.com sever sets 5-6 separate set-cookie headers and when u get it thru response.header s then all of them are pushed in to a single set-cookie header, i want to split them back and send them to the browser as 5 seperate set-cookie headers like the server had sent, but since every site has its own style for cookies am not sure i can write a regex which will work all the time. dats y i was looking for an alternate method.
Thanks again.
Plater 7,872
Recognized Expert Expert
Hmm, I would guess it was done because the collection object requires a unique key for the headers. (Really I suspect it is bad form to have multiple header lines with the same name: 'Set-Cookie')
At any rate, it seems to comma delimenate them so a simple .Split() on that string for commas should give you all the various cookie headers. EDIT: I just noticed a problem with this, guess it's not as simple as i thought.
So using: -
string n = "";
-
string[] pieces = resp.GetResponseHeader("Set-Cookie").Split(',');
-
for (int i = 0; i < pieces.Length; ++i)
-
{
-
n += "Set-Cookie: " + pieces[i] + "\r\n";
-
}
-
I was able to get: -
Set-Cookie: MYUSERINFO=; domain=.myspace.com; expires=Wed
-
Set-Cookie: 19-Jan-2005 08:28:17 GMT; path=/
-
Set-Cookie: MYUSERINFO=; domain=myspace.com; expires=Wed
-
Set-Cookie: 19-Jan-2005 08:28:17 GMT; path=/
-
Set-Cookie: USER=; domain=.myspace.com; expires=Wed
-
Set-Cookie: 19-Jan-2005 08:28:17 GMT; path=/
-
Set-Cookie: USER=; domain=myspace.com; expires=Wed
-
Set-Cookie: 19-Jan-2005 08:28:17 GMT; path=/
-
Set-Cookie: MSCulture=IP=74.92.34.25&IPCulture=en-US&PreferredCulture=en-US&PreferredCulturePending=&Country=US&ForcedExpiration=0&timeZone=0&USRLOC=QXJlYUNvZGU9NjAzJkNpdHk9QnJvb2tsaW5lJkNvdW50cnlDb2RlPVVTJkNvdW50cnlOYW1lPVVuaXRlZCBTdGF0ZXMmRG1hQ29kZT01MDYmTGF0aXR1ZGU9NDIuNzQ5NCZMb25naXR1ZGU9LTcxLjY2ODEmUG9zdGFsQ29kZT0wMzAzMyZSZWdpb25OYW1lPU5I; domain=.myspace.com; expires=Mon
-
Set-Cookie: 11-Feb-2008 14:33:09 GMT; path=/
-
Set-Cookie: SessionDDF1=cc057dfe6d288a6385cf9b3706676a3c5168edc0b1fd4516; domain=.myspace.com; path=/
-
Set-Cookie: SessionDDF2=d4284c7faeaa883d1c57e9f40849a63d6dc1394e38b5fbe9; domain=.myspace.com; path=/; expires=Monday
-
Set-Cookie: 04-Aug-08 14:33:09 GMT
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: hanaa |
last post by:
Hi
I'm tyring to create a collection of an object inside an object I have tried to use the code written in the following URL
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vaconcreatingyourowncollectionclass.as
its working fine when I test it from VB.net but my application is a web-application , I tried to use the same classes that I have created and tested in VB.Net the collection counter is always set to 1 even...
|
by: Randy Chow |
last post by:
Hello everyone I was wondering if anyone has come across my problem? I
programmed a Windows Service that uses httpWebRequest and httpWebResponse in
VB.NET. Everything works fine until I use the webresponse object. What the
Windows Service does is when the timer in the windows service elapses, the
request to the website is made and a response is retrieve in a simple
myhttpWebrequest.GetResponse(). I don't even do anything with the...
|
by: Jason Manfield |
last post by:
For some URLs
(e.g.http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO2005028634),
the content length for the HttpWebResponse I get with request.GetResponse in
empty. The response.GetResponseStream() also empty. However, I am able to
open the URL in the browser (the URL address remains the same; it is not
redirected)
Here is the code snippet:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
|
by: Jason Manfield |
last post by:
Why does HttpWebResponse.CharacterSet always return ISO-8859-1? I am
accessing a Chinese Web site (http://cn.yahoo.com) -- View Source in IE shows
the character set to be "gb2312", but the HttpWebResponse shows it to be
ISO-8859-1. Websites like www.cnn.com also show the character set to
ISO-8859-1
Here is the code snippet:
string pageAddress = "http://cn.yahoo.com";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
|
by: Nuno Magalhaes |
last post by:
Hello,
In a simple thread I have a code like the one below:
public void ProtectionRun()
{
while(true)
{
//Sleep thread for one minute
//Thread.Sleep(60000);
HttpWebRequest
| |
by: STEVE.KING |
last post by:
Greetings:
I need to download an executable and some other binary files (a C++
DLL) from a virtual directory in my WinForms application. No-Touch
Deployment manages my .NET code fine but auxilliary files such as these
must be downloaded "manually" in my code. My text-based files download
fine but I've ran into a problem downloading an .EXE. When it
downloads the file size is the same but it has been altered somehow
because a) the...
|
by: Joe |
last post by:
I'm creating an application that HTTP posts some form data, and is
supposed to read the response. When I actually do this form posting from
a web page, I get the response exactly as I would expect. However, when I
try to do this form posting programmatically, I get a WebException where
the Status is set to ServerProtocolViolation. As far as I can tell, this
status tells me that the response is not a standard HTTP response. Ok, I
know...
|
by: stewart.fay |
last post by:
Dear all,
I am using the HttpWebRequest and HttpWebRequest to send an XML request
to an ASPX page.
When I use the browser and add my XML request the request is posted
fine and an answer is retrieved.
However, when I use the code below I get an timeout error on the line:
oWebResponse = DirectCast(oWebRequest.GetResponse, HttpWebResponse)
|
by: Morgan Cheng |
last post by:
I found one issue about HttpWebResponse.
I tried to get a huge webpage (i.e. http://wx.msn.com) with
HttpWebRequest timeout set; reading the response stream is still
controlled by timeout. However, the HttpWebResponse.Close takes ages.
I suppose HttpWebResponse want to do a clean resouce clean-up. So, if
the website doen't finish sending chuckes of HTTP packets, the client
would not return from Close().
Is there anybody clear about the...
|
by: deepunarayan |
last post by:
Hi I have Problem in ASP.
I have created a Multi choice Question page in ASP with Submit button.
When I submit my page the User Selected values will be taken to the other page where validation will happen.
My problem is, the number of question will be dynamic and I need to validate the scores and give the final scores.
I tried to use a form collection via for each and validate with my answers but could nt successful
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |