0

I'm using HttpListener with my own framework to handle http requests.

Only two requests: sign in and sign up.

While signing up successfully, I will put [id, studentId, name] three cookies in the response cookie, but it turns out only one I will finally put in, that's [id].

Here's my codes where I put my cookies:

private void saveStudentIdentityToCookie(Student student)
{
    idCookie = new Cookie("id", student.id) {Expires = DateTime.Now.AddMonths(1)};
    nameCookie = new Cookie("name", student.name) { Expires = DateTime.Now.AddMonths(1)};
    studentIdCookie = new Cookie("studentId", student.studentId) { Expires = DateTime.Now.AddMonths(1)};
    response.AppendCookie(idCookie);
    response.AppendCookie(nameCookie);
    response.AppendCookie(studentIdCookie);
    Log.d(TAG, "Student " + student + " saved into the cookie.");
}

And here's my result, I view it using the google extension - EditThisCookie

enter image description here

It shows that I only got one cookie, please take a look where did I go wrong, thanks a lot.

OOD Waterball
  • 707
  • 1
  • 11
  • 31
  • Possible duplicate of [Storing multiple values in cookies](https://stackoverflow.com/questions/1173729/storing-multiple-values-in-cookies) – BugFinder Apr 16 '18 at 07:37
  • @BugFinder Sorry, I have edited my title for more clearness, I'm using no framework, but pure HttpListener. I don't see duplicated contents in that post. – OOD Waterball Apr 16 '18 at 07:43
  • 1
    I'd suggest to first verify presence of cookies via some more reliable tools, such as chrome dev console. – Evk Apr 16 '18 at 07:46
  • The framework wasnt the important part - how to store the multiple cookies was – BugFinder Apr 16 '18 at 07:46
  • @BugFinder But I cannot use **HttpCookie** class, in HttpListener lib there is only **Cookie** class and cannot be used in that way. (One cookie can only have one value, so I have to init many cookies as my codes do.) – OOD Waterball Apr 16 '18 at 07:55
  • @Evk thanks for suggestion, I've checked on chrome network activity and still found only one cookie. – OOD Waterball Apr 16 '18 at 07:57
  • 1
    According to[microsoft](https://social.msdn.microsoft.com/Forums/en-US/b08e14fd-e6af-4375-a646-ae4a231505c3/how-to-make-httplistenerresponse-work-with-multiple-cookies-?forum=ncl) you need to add them as headers not cookies – BugFinder Apr 16 '18 at 07:59

0 Answers0