Need Help with HTTPClient.h and storing cookies

Im very new to Arduino. Using an ESP32, Im trying to login to a network device to read its log file. To login to the device I need to simulate a web browser with cookies.

The ESP32 is connecting to WiFI correctly, and Im including the HTTPClient.h file

Using http.begin I am able to browse to the device login page, but I dont know how to store the successful login in a cookie.

I can successfully do it in PEARL using CURL (my code is below). Can someone help me port this to ESP32

use strict qw/refs/;
use HTTP::Cookies;
use LWP::UserAgent;
use HTTP::Request::Common qw/POST GET/;

my $Browser = LWP::UserAgent->new(
cookie_jar => HTTP::Cookies->new,
requests_redirectable => [],
timeout => 10,
pragma => "no-cache",
max-age => 0,
agent => "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0"

my $Page = $Browser->request(GET $Authenticate);

there is no special support for cookie on esp32, but cookie is just a http header

you should collect the header field in the first response and reuse them in the next request

there are two methods for that:

    void addHeader(const String& name, const String& value, bool first = false, bool replace = true);

    /// Response handling
    void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);

I've never done this on a client, but this might give a first idea

const char* headers[] = {"Set-Cookie"};
client.collectHeaders(headers, sizeof(headers)/ sizeof(headers[0]));

parse the content and extract the information from headers.
add the information based on the wikipedia example to the next request:

client.addHeader("Cookie", "content");

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.