How can i get and set a cookie from a web browser with client.write and client.read?

Hi i want to know if i can get a cookie from client.write and client.readstring?
here is my code

import processing.net.*;
import processing.video.*;
import java.io.File;
Server myServer;
int nb = 0;
byte[] logo;


void setup() {
  size(200, 200);
  myServer = new Server(this, 80);
  println("ip: " + Server.ip());
  println();
}

void draw() {
  Client client = myServer.available();
  if(client != null)
  {
    String info = client.readString();
    String text = "A html code";
    client.write("HTTP/1.1 200 OK\r\n");
    client.write("Content-Length: "+ text.length() +"\r\n");
    client.write("Content-Type: text/html\r\n\r\n");
    client.write(text);
    client.stop();
    println(info);
  }
}
void deleteDirectoryRecursionJava6(File file) {
  if (file.isDirectory()) {
    File[] entries = file.listFiles();
    if (entries != null) {
      for (File entry : entries) {
        deleteDirectoryRecursionJava6(entry);
      }
    }
  }
}

If you set a local server and access the app using your browser, then you can add the following lines to your code and then you are able to see the cookies using your browser’s advanced tools:

    String info = client.readString();
    String text ="<meta http-equiv=\"set-cookie\" content=\"HolidayGlaze=;\">";
    text +=  "<meta http-equiv=\"set-cookie\" content=\"Holiday2018=Good%20yummies; expires=Sat, 25-Nov-2023 12:00:00 GMT;\">";
    text += "A html code";

I just tested this using localhost. I have to set the port to 8081 as 80 and 8080 were taken.

Relevant: https://www.willmaster.com/library/cookies/setting-a-cookie-using-only-html.php

Kf

2 Likes