Jump to content
  • Advertisement
Sign in to follow this  
WarGames

C++ WinSock question

This topic is 4439 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering- using WinSock, what's the command to send a cookie? Also, is there an easy way to access a user's cookies? Finally, I've been wondering how to sort out the html received from a webpage. I was thinking of writing a function that would check a character to see if it begins a HTML tag, which would in turn toggle a boolean variable. The characters following would be deleted, but if the next one is the ending HTML tag character, the variable is toggled again. Hope that isn't too confusing. Anyway, there isn't an easier way to do that, is there? Before you think that I'm trying to steal everyone's personal information, I'm just wondering how to send a cookie to a website so that it logs the program in. This is all completely legitimate. Not sure if I should put this here or in For Beginners- sorry if it shouldn't be here.

Share this post


Link to post
Share on other sites
Advertisement
Try posting it here as well:

http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.win32.programmer.networks

And as to your question... I'm not sure, sorry.

Share this post


Link to post
Share on other sites
i don't even know if Winsock has a "cookie" function but i suspect it doesn't (it is more low-level that that).

but either way you ought to post this in the networking forum.

Share this post


Link to post
Share on other sites
Winsock is indeed far lower level than HTTP cookies. However, you can indeed retrieve (and even set) cookies manually by implementing the appropriate parts of the HTTP specification (RFC2616).

In particular, to read a cookie, you will look in the HTTP header for the Set-Cookie field and parse it using the standard key=value&key2=value2 format used for encoding associated pairs in HTTP. The server will pass a Set-Cookie to you when you are expected to set a cookie value. Henceforth, you are expected to return a list of all values you have set for the current site in the Cookie field of any request you send to the server.


Your plan for stripping HTML tags will work, but note that it may be greedy and recognize invalid "tags" - for instance <blork> is not a valid HTML tag but your solution would eliminate it. I would recommend looking for a known and reliable library function to handle this for you.

In fact, setting and unsetting cookies is best handled by a library as well - directly implementing HTTP at the socket layer is error-prone and requires some very intimate knowledge of the RFCs involved. Unless absolutely necessary, prefer using a library here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!