Results 1 to 9 of 9

Thread: Creating Cookies.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    Hiyas, I was just wondering if anyone can tell me how to create a cookie in vb, rather than vbscript? for example when you send a http request to a website via winsock and you get one back containg data saying to create a cookie with certain data? how do you create this cookie just in vb? or don't you need to (ie: just send back certain data instead?).

    any help on this is apprecaited.

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    I've tried this on several ocasions...and all i can say is it's not easy. You would have to know the exact contents of the cookie (get a packet sniffer to sniff while recieving the cookie) then you would have to send data through winsock, wait for a reply then send more data. It's not that hard...it's just a long process.

    Gl,
    D!m
    Dim

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    Hey Dim thanx for replying

    I found some api calls for Setting and Getting Cookies, I am just not sure how to use the one to set the cookie, as I couldn't find an example on how to use it.

    the api calls:

    Code:
    Public Declare Function InternetSetCookie Lib "wininet.dll" Alias "InternetSetCookieA" (ByVal lpszUrlName As String, ByVal lpszCookieName As String, ByVal lpszCookieData As String) As Boolean
    Public Declare Function InternetGetCookie Lib "wininet.dll" Alias "InternetGetCookieA" (ByVal lpszUrlName As String, ByVal lpszCookieName As String, ByVal lpszCookieData As String, lpdwSize As Long) As Boolean
    I gather the lpszUrlName would be for the url or the url title, but its the lpszCookieName and lpszCookieData I don't really know what to put for. for example i was running a fake proxy I some time use (just shows the data being sent and recieved) to try to find a site that sent a set cookie command I found one the command:

    Set-Cookie: IPB=1; expires=Thursday, 14-Sep-00 01:50:17 GMT

    so which part of it would I use for the cookie name? and which part would I use for the cookie data? and which part for the cookie name?

    thanx for any help.

  4. #4
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Go toy your browser options and set it so it prompts you when a cookie is being sent, that will tell you the hame of the cookie and the data. You can also packet sniff to find that information. I don't have time right now to attempt that but if you don't find a way by tonight, i'll be glad to assist you.


    Gl,
    D!m
    Dim

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    thanx for replying again dim

    I figured out what the data save was for that particular site by going into my cookie folder and having a look it was:

    Code:
    IPB
    1
    http://www.thesitehere.com/
    0
    1074862848
    29362612
    927656640
    29362410
    *
    I just don't see where all those numbers come into out of this command:
    Set-Cookie: IPB=1; expires=Thursday, 14-Sep-00 01:50:17 GMT
    I get the first three line, the IPB text then the value of it then the site address, and I am guessing the rest has something to do with the date, I just don't get why those numbers.

  6. #6
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Ok, if you are using IE follow these instructions:
    Go to "Tools" then "Internet Options" then Click the "Custon Level" button. Scroll down to the cookie options and select "Prompt" for both types of cookies. Then close the browser. Go to your Temp internet Files folder and deleted everything from there...and go to the cookie folder and delete all the cookies. Then open it again and go to the site that sends the cookie...when a prompt comes up asking if you want to accept it, click "More Info" and you will be shown the contents of the cookie(name/data/date). Then use the API or winsock to send out the cookie through vb.
    Inform me if you get/don't get it working.

    D!m
    Dim

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    hey dim thanx for telling me how to do that

    but yeah it not just one particular cookie I am trying to send out / save, I am trying to make my own text based browser from scratch just using the winsock control, and my connection gets pretty slow some times so when my connection is being slow I could use my text browser instead of ie and not see the pictures, but yeah I get alot of "Your Browser Does Not Support Cookies" Errors at the moment, so I am trying to work out why ie actually used all those numbers as well, so I can save the cookie correctly.

    but thanx for your help dim

  8. #8
    New Member
    Join Date
    Feb 2000
    Location
    Australia
    Posts
    10
    Ah Crypt - I found your article because I'm trying to find out how to receive a cookie after using a POST operation to login to a particular site... but what you're trying to do is completely unnessecary - If you want a browser thats text only, just go to options in MSIE and turn off images in the advanced section and MSIE won't download or display any images...

    might be a tad simpler if thats all you're trying to do.
    "Hello, I would like to buy a fish licence please..."

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    dang this is an old topic, anyways I found the answer to my problem, the set cookie api, converts it into the correct format, but anyways.

    Hiya Reprise, I don't know you could turn the pictures off but now u tell me yeah I it does seem uneccessary but I wanted to create my own browser completely from scratch anyways, with out using a browser control.

    but to recieving the cookie once you have used post, well this is how I do it, in the general part of the program put something like

    Dim UrlData as String

    then in your data arrival just get the data and add it to the urldata string.

    ie:

    Dim WinsckData as string
    Winsock1.GetData WinsckData
    UrlData = UrlData & WinsckData

    then in your winsock close event you'd have something like:

    Code:
    Dim Cookie As String
    If InStr(1, LCase(UrlData), "set cookie:") <> 0 Then 'If the urldata has a cookie to be set in it.
        Cookie = Mid$(UrlData, InStr(1, LCase(UrlData), "set cookie: ") + Len("Set Cookie: ")) 'Trims it out of the string
        If InStr(1, Cookie, vbCrLf) <> 0 Then 'If ther is a carriage return in the string then
            Cookie = Mid$(Cookie, 1, InStr(1, Cookie, vbCrLf) - 1)
        End If
    
        MsgBox Cookie
    UrlData = ""
    End If
    that should do the trick to extract the cookie.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width