Send cookie with WebRequest

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    Send cookie with WebRequest

    string m_request = some_web_page;

    HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(m_request );

    HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();



    Which works fine, but I need to set and send a cookie with the WebRequest.
    How do I do that?


  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: Send cookie with WebRequest

    Dave wrote:
    string m_request = some_web_page;
    >
    HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(m_request );
    >
    HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
    >
    Which works fine, but I need to set and send a cookie with the WebRequest.
    How do I do that?
    HttpWebRequest has a property CookieContainer which is of type
    CookieContainer that has an Add method ... !

    Arne

    Comment

    • Steven Cheng [MSFT]

      #3
      RE: Send cookie with WebRequest

      Hi Dave,

      As for HttpWebRequest component, if you want to maintain cookies between
      multiple WebRequest instances(and webrequest calls), you need to create an
      CookieContainer instance and attach it to the WebRequest.Cook ieContainer
      property.

      Also, if you want the cookies to share between multiple WebRequest
      instances, you need to make sure all of those WebRequest instances use the
      same cookie container.

      here are some web thread that also mentioned some code that use
      CookieContainer :


      #Establishing cookie based session with WebServices and HttpWebRequest


      #Help needed with cookies and WebRequest


      If you have any further questions, welcome to post here.

      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.


      --------------------
      >From: "Dave" <DWeb@newsgroup .nospam>
      >Subject: Send cookie with WebRequest
      >Date: Thu, 8 May 2008 19:04:08 -0400
      >Lines: 12
      >
      >string m_request = some_web_page;
      >
      >HttpWebReque st request = (HttpWebRequest )WebRequest.Cre ate(m_request );
      >
      >HttpWebRespons e response = (HttpWebRespons e)request.GetRe sponse();
      >
      >
      >
      >Which works fine, but I need to set and send a cookie with the WebRequest.
      >How do I do that?
      >
      >
      >

      Comment

      • Steven Cheng [MSFT]

        #4
        RE: Send cookie with WebRequest

        Hi Dave,

        Have you got progress on this issue or does the suggestion in our previous
        reply help you some? If you need any further help on this, welcome to post
        here.

        Sincerely,

        Steven Cheng

        Microsoft MSDN Online Support Lead


        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Gain technical skills through documentation and training, earn certifications and connect with the community

        ications.

        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.

        --------------------
        >Organization : Microsoft
        >Date: Fri, 09 May 2008 04:10:08 GMT
        >Subject: RE: Send cookie with WebRequest
        >
        >Hi Dave,
        >
        >As for HttpWebRequest component, if you want to maintain cookies between
        >multiple WebRequest instances(and webrequest calls), you need to create an
        >CookieContaine r instance and attach it to the WebRequest.Cook ieContainer
        >property.
        >
        >Also, if you want the cookies to share between multiple WebRequest
        >instances, you need to make sure all of those WebRequest instances use the
        >same cookie container.
        >
        >here are some web thread that also mentioned some code that use
        >CookieContaine r:
        >
        >
        >#Establishin g cookie based session with WebServices and HttpWebRequest
        >http://blogs.msdn.com/adarshk/archiv...24/219714.aspx
        >
        >#Help needed with cookies and WebRequest
        >http://forums.microsoft.com/MSDN/Sho...99324&SiteID=1
        >
        >If you have any further questions, welcome to post here.
        >
        >Sincerely,
        >
        >Steven Cheng
        >
        >Microsoft MSDN Online Support Lead
        >
        >
        >Delighting our customers is our #1 priority. We welcome your comments and
        >suggestions about how we can improve the support we provide to you. Please
        >feel free to let my manager know what you think of the level of service
        >provided. You can send feedback directly to my manager at:
        >msdnmg@microso ft.com.
        >
        >============== =============== =============== ======
        >Get notification to my posts through email? Please refer to
        >http://msdn.microsoft.com/subscripti...ault.aspx#noti
        f
        >ications.
        >
        >Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        >where an initial response from the community or a Microsoft Support
        >Engineer within 1 business day is acceptable. Please note that each follow
        >up response may take approximately 2 business days as the support
        >professional working with you may need further investigation to reach the
        >most efficient resolution. The offering is not appropriate for situations
        >that require urgent, real-time or phone-based interactions or complex
        >project analysis and dump analysis issues. Issues of this nature are best
        >handled working with a dedicated Microsoft Support Engineer by contacting
        >Microsoft Customer Support Services (CSS) at
        >http://msdn.microsoft.com/subscripti...t/default.aspx.
        >============== =============== =============== ======
        >This posting is provided "AS IS" with no warranties, and confers no rights.
        >
        >
        >--------------------
        >>From: "Dave" <DWeb@newsgroup .nospam>
        >>Subject: Send cookie with WebRequest
        >>Date: Thu, 8 May 2008 19:04:08 -0400
        >>Lines: 12
        >>
        >>string m_request = some_web_page;
        >>
        >>HttpWebReques t request = (HttpWebRequest )WebRequest.Cre ate(m_request );
        >>
        >>HttpWebRespon se response = (HttpWebRespons e)request.GetRe sponse();
        >>
        >>
        >>
        >>Which works fine, but I need to set and send a cookie with the
        WebRequest.
        >>How do I do that?
        >>
        >>
        >>
        >
        >

        Comment

        Working...