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

  • Home
  • SEARCH
  • 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 8322185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:17:44+00:00 2026-06-08T23:17:44+00:00

Where in my C# code do I need to put the code for setting

  • 0

Where in my C# code do I need to put the code for setting cookies? Firefox shows three cookies when I’m logged in to the system.

Login page

system.local/interface/Login.php

POST /interface/Login.php HTTP/1.1
Host: system.local
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://system.local/interface/Login.php
Cookie: language=en_US.UTF-8; StationID=06ae3ed4d72a33dd951572df84a13725
Content-Type: application/x-www-form-urlencoded
Content-Length: 71
user_name=user&password=password123456&language=en&action%3Asubmit=Submit

GET response from index.php when logged in

http://system.local/interface/index.php

GET /interface/index.php HTTP/1.1
Host: system.local
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: system.local/interface/Login.php  
Cookie: language=en_US.UTF-8; StationID=06ae3ed4d72a33dd951572df84a13725; SessionID=3783a8fea972fb99779f7dd3078ed53c

Where to put the cookie(s) in this code?

string url;
string cookieHeader;
string formparam;
HttpWebRequest request;
HttpWebResponse response;
byte[] bytes;

url = "http://system.local/interface/Login.php";
formparam = string.Format("user_name=" + textBox1.Text + "&password=" + textBox2.Text + "&language=en&action%3Asubmit=Submit");
request = (HttpWebRequest)HttpWebRequest.Create(url);
var cookies = new CookieContainer();
request.ContentType = "Content-Type: application/x-www-form-urlencoded";
request.Method = "POST";
bytes = Encoding.ASCII.GetBytes(formparam);
request.ContentLength = bytes.Length;
request.KeepAlive = true;

using (Stream os = request.GetRequestStream())
{
    os.Write(bytes, 0, bytes.Length);
}

response = (HttpWebResponse)request.GetResponse();
cookieHeader = response.Headers["Set-Cookie"];


request = (HttpWebRequest)WebRequest.Create("http://system.local/interface/Login.php");
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response.Cookies);
request.Headers.Add("Cookie", cookieHeader);

response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    //richTextBox1.Text = reader.ReadToEnd().Trim();
}
  • 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-06-08T23:17:47+00:00Added an answer on June 8, 2026 at 11:17 pm

    Set the CookieContainer field on every request, and it should automatically add the cookies from the header. Use the same CookieContainer instance every time and it will maintain its state across multiple requests. You don’t need to mess with Cookie or set-cookie header values, because the CookieContainer handles that automatically if it’s assigned to the request cookie container.

    var cookies = new CookieContainer();
    
    request.CookieContainer = cookies;
    ...
    response = (HttpWebResponse)request.GetResponse();
    // no need to manually read Cookie header, CookieContainer handles that.
    
    request = ...
    request.CookieContainer = cookies;
    // no need to manually set/populate CookieContainer, just use the same instance.
    ...
    response = (HttpWebResponse)request.GetResponse();
    // etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kind of need help understanding what this code actually outputs. Does it out put
I need to export a gridview to excel, I put the return html code
I'm writing some terrible, terrible code, and I need a way to put a
i have put that url http://pvpcoach.com/notification.php in Instant Payment Notification setting in my profile
Both my Rails model and controller code need to write files to the file
I need code for read json data from url in ios (objective c) If
In my code I need to compare string letters but my problem is that
I have a code that need to be translated from C to Cpp, and
In the following code I need to print output from the variables $stout ,
The C code i need to convert into Java is: typedef struct { short

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.