Duplicating COOKIES in WODHTTP - WeOnlyDo Discussion board

Duplicating COOKIES in WODHTTP (wodWebServer / wodWebServer.NET)

by Joshu, Monday, October 10, 2011, 01:29 (4582 days ago)

So here is the problem, webpages are getting smarter, and smarter. There is a major issue with the COOKIE support within wodHttp. I am going to give you an example + a fix that still has issues.

So for example I will use the name of a cookie and call it wodCOOK . This is what the WEBSITE would reply back. With varying values.

So say I hit website, they reply with cookie wodCOOK=12345 .
I then visit the next page on the website and they reply with wodCOOK=9987666 .

If I already added wodCOOK=12345 into the cookies, it will send BOTH of those cookies. Is there a function to just UPDATE that specific cookie. If it finds the same cookie NAME then it should update the VALUE. That is a major flaw.

Here is the simple work-around I have done, but it too has a few errors. It continues to send the initial cookie. Any help would be appreciated, or an updated method to save/send cookies.

For Each oldcookie In wodHttp(Index).Response.Cookies
If InStr(wodHttp(Index).Request.Cookies.ToString, oldcookie.Name) Then
'cookie already in list, if add again it will have 2 cookies
'needs to updating cookie
Else
'new cookie
wodHttp(Index).Request.Cookies.Add oldcookie.Name, oldcookie.Value
End If
Next oldcookie

Re: Duplicating COOKIES in WODHTTP

by woddrazen, Monday, October 10, 2011, 09:09 (4582 days ago) @ Joshu

Hi Joshu,


Why don't you simply use Remove Method and remove this old duplicate cookie?

More help for HttpCookies object Remove Method you can find here:
http://www.weonlydo.com/HttpDLX/Help/wodHttpDLX-HttpCookies-Remove.html

Let us know how it goes.


Regards,
Drazen

Re: Duplicating COOKIES in WODHTTP

by joshu, Wednesday, October 12, 2011, 23:03 (4579 days ago) @ woddrazen

I have tried but couldn't get it to remove the correct cookie. Can you do this to show an example?

Hi Joshu,


Why don't you simply use Remove Method and remove this old duplicate cookie?

More help for HttpCookies object Remove Method you can find here:
http://www.weonlydo.com/HttpDLX/Help/wodHttpDLX-HttpCookies-Remove.html

Let us know how it goes.


Regards,
Drazen

Re: Duplicating COOKIES in WODHTTP

by wodDamir, Wednesday, October 12, 2011, 23:29 (4579 days ago) @ joshu

Joshu,

I'm not really sure what to show exactly. Remove method accepts cookie index, and removes it from the collection. You can simply iterate through your Cookies collection, and in case there is double remove it using Remove method.

The other way would be to set Cookie value instead of removing/adding a new cookie in collection. You can do that simply by setting it's Value property (http://www.weonlydo.com/HttpDLX/Help/wodHttpDLX-HttpCookie-Value.html).

Can you please try that?

Regards,
Damba

Re: Duplicating COOKIES in WODHTTP

by joshu, Thursday, October 13, 2011, 01:10 (4579 days ago) @ wodDamir

I don't see how to get the exact location of the cookie. I wish you could just do like
Cookie.remove cool
That doesn't work. Your site says you can remove by the value name but that doesn't work

Can you show an example of how to remove with the example i posted earlier.

Joshu,

I'm not really sure what to show exactly. Remove method accepts cookie index, and removes it from the collection. You can simply iterate through your Cookies collection, and in case there is double remove it using Remove method.

The other way would be to set Cookie value instead of removing/adding a new cookie in collection. You can do that simply by setting it's Value property (http://www.weonlydo.com/HttpDLX/Help/wodHttpDLX-HttpCookie-Value.html).

Can you please try that?

Regards,
Damba

Re: Duplicating COOKIES in WODHTTP

by wodDamir, Thursday, October 13, 2011, 08:42 (4579 days ago) @ joshu

Joshu,

Why don't you try something like:

[php]Dim cook as HttpCookie = new HttpCookie
For each cook in http1.Cookies
if cook.Name = some_name AND cook.Value = old value then
cook.Value = new value
end if
Next[/php]

Can you try something like that?

Regards,
Damba

Re: Duplicating COOKIES in WODHTTP

by Joshu, Saturday, October 15, 2011, 05:58 (4577 days ago) @ wodDamir

This doesnt work. I am trying this but if you just changed the cook.value then that wouldn't change the one in .request.cookies, thats the one i am trying to fix.

please help

Joshu,

Why don't you try something like:

[php]Dim cook as HttpCookie = new HttpCookie
For each cook in http1.Cookies
if cook.Name = some_name AND cook.Value = old value then
cook.Value = new value
end if
Next[/php]

Can you try something like that?

Regards,
Damba

Re: Duplicating COOKIES in WODHTTP

by woddrazen, Saturday, October 15, 2011, 11:43 (4577 days ago) @ Joshu

Joshu,


Why don't you then try something like this:
[code]http1.Request.Cookies.Add http1.Response.Cookies(x).Name, your value [/code]

Drazen

Re: Duplicating COOKIES in WODHTTP

by Joshu, Sunday, October 16, 2011, 02:33 (4576 days ago) @ woddrazen


That is the issue I am having. I need to know the index of the cookie to set it. Is there a way to get the cookie index?

Joshu,


Why don't you then try something like this:
[code]http1.Request.Cookies.Add http1.Response.Cookies(x).Name, your value [/code]

Drazen

Re: Duplicating COOKIES in WODHTTP

by Joshu, Sunday, October 16, 2011, 05:37 (4576 days ago) @ Joshu

Also if I just do another ADD without REMOVING the previous cookie, then it will have 2 cookies with the same name but different values....


That is the issue I am having. I need to know the index of the cookie to set it. Is there a way to get the cookie index?

Joshu,


Why don't you then try something like this:
[code]http1.Request.Cookies.Add http1.Response.Cookies(x).Name, your value [/code]

Drazen

Re: Duplicating COOKIES in WODHTTP

by woddrazen, Sunday, October 16, 2011, 16:14 (4576 days ago) @ Joshu

Joshu,


You need to loop thought cookies collection and find cookie you want to remove. Then you can remove it and add new one.

Something like Damba show you inside his last example.


Drazen