Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4617172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:05:15+00:00 2026-05-22T02:05:15+00:00

I asked a question on here earlier and got some fantastic responses. I’ve since

  • 0

I asked a question on here earlier and got some fantastic responses. I’ve since been diddling Visual C# and ran into a bit of a problem.

Here I made a simple page that sets a cookie.

If you go to it and then refresh, it’ll see if there’s a cookie present and change the output html.

Now, I want my C# program to fetch a page, get a cookie and then re-visit the page again with the cookie that is set, so that my page presents me the "updated" message. I accomplished phase one via:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        WebRequest request = WebRequest.Create("http://www.binarywatch.biz/forms/cookietest.php");

        request.Credentials = CredentialCache.DefaultCredentials;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();

        MessageBox.Show(responseFromServer, "Derp");

        reader.Close();
        dataStream.Close();
        response.Close();
    }

So at this point I have the page html but I’m a bit lost as to how to go about getting a cookie (Something to do with CookieContainer() ? ) and then making the page know that I have it (by adding it to the httpwebrequest somehow?)

I tried googling it of course but a LOT of the answers I find are about ASP.NET / web programming and that’s not what I need.

PS. What’s the difference between WebRequest and HttpWebRequest?

I hope this isn’t too noobish, I’m a bit stumped.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:05:16+00:00Added an answer on May 22, 2026 at 2:05 am

    according to MSDN you’d first create an instance of the CookieContainer before calling getResponse. After that you should be able to get cookie data out of the CookieContainer you created.

    (request as HttpWebRequest).CookieContainer = new CookieContainer();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    CookieCollection cookies = (request as HttpWebRequest).CookieContainer.GetCookies("www.binarywatch.biz");
    string myValue cookies["myCookie"].Value
    

    You should be able to re-use the same CookieContainer object to make sure the server keeps getting access to the cookies.

    The GetCookies(domain) is needed as a single CookieContainer is able to store separate cookies safely for multiple domains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a question earlier which elicited some great responses. Here's the earlier question
I asked a question earlier yesterday and got some very good answers for sure.
Earlier today I asked a question and got a good answer here . However
I asked a question here earlier today and got that fixed, but now I
I asked a similar question earlier here , and it got me down the
I asked a question earlier today here . However, what I neglected to check
Related to a question I asked earlier here , I've found a problem which
I asked a very similar question here but since it is such a fundamental
I asked this goofy question earlier today and got good answers. I think what
This is a follow up to a question I asked earlier seen here: Confused

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.