Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cookies and HttpWebRequest

Cookies and HttpWebRequest

Scheduled Pinned Locked Moved C#
comxmlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brian Delahunty
    wrote on last edited by
    #1

    Hey Lads, I'm using HttpWebRequest in a thick client application and just wondering if there is a simple way to get the request to automatically include an IE cookie??? Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
    http://www.briandela.com/pictures Now with a pictures section :-D
    http://www.briandela.com/rss/newsrss.xml RSS Feed

    H 1 Reply Last reply
    0
    • B Brian Delahunty

      Hey Lads, I'm using HttpWebRequest in a thick client application and just wondering if there is a simple way to get the request to automatically include an IE cookie??? Regards, Brian Dela :-) http://www.briandela.com IE 6 required.
      http://www.briandela.com/pictures Now with a pictures section :-D
      http://www.briandela.com/rss/newsrss.xml RSS Feed

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Not through the BCL, no. You can P/Invoke InternetGetCookie:

      [DllImport("wininet.dll", CharSet=CharSet.Auto)]
      private static extern bool InternetGetCookie(
      string url,
      string cookieName,
      [Out] string cookieData,
      ref int dataSize);

      That third parameter should not use out, mind you - it should be marshaled as an [out] param using the OutAttribute only, otherwise the CLR will crash. See the Platform SDK for usage, but it's really pretty easy to do. To easily allocate a string of a certain size, you can use new string('\0', _size_) or declare those as StringBuilders and modify your source accordingly. Then you can parse and include these in your CookieContainer for use with the HttpWebRequest.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups