TAdvWebBrowser Access Violation on NavigateWithData

Hi,

I'm trying to pass some custom variables like the user_id into my web application using the TAdvWebBrowser component. I want to do this by setting cookies manually in the request headers. Here's the code I'm using:

procedure TForm3.AdvWebBrowser1Initialized(Sender: TObject);
begin
  FHeaders := TStringList.Create;
  FHeaders.Values['Cookie'] := 'Token=TOKENVALUE; userId=myUserId';

  AdvWebBrowser1.NavigateWithData(
    'http://localhost:3000',
    'GET',
    nil,
    FHeaders
  );
end;

However, as soon as the NavigateWithData method is called, I get an Access Violation error:

Exception class $C0000005 with message 'access violation at 0x00d6dc4f: read of address 0x00000000' in Project2.exe.

Has anyone encountered this issue before? Am I using the NavigateWithData method correctly, or is there a better way to pass cookies to a site loaded with TAdvWebBrowser?

Thanks in advance!

Hi,

The nil parameter needs to change to an empty string, because it expects a stream to be initialized otherwise.

procedure TForm3.AdvWebBrowser1Initialized(Sender: TObject);
begin
  FHeaders := TStringList.Create;
  FHeaders.Values['Cookie'] := 'Token=TOKENVALUE; userId=myUserId';

  AdvWebBrowser1.NavigateWithData(
    'http://localhost:3000',
    'GET',
    '',
    FHeaders
  );
end;

I recently discovered that as soon as I use AddCookie, only one cookie can be set successfully. When I try to add a second cookie like in the example below:

testcookie := NewCookie('username', 'username', 'localhost', '/', Now + 1);
testcookie2 := NewCookie('username2', 'testcookie2', 'localhost', '/', Now + 1);

WebBrowser.AddCookie(testcookie);
WebBrowser.AddCookie(testcookie2);

No cookie gets added at all.
What’s strange is that setting a single cookie works without any issues. However, for the sake of clean structure, I’d like to pass four different cookies to my page.

Unfortunately, setting cookies via headers didn’t work either.

Additional info:
NewCookie is a helper function I wrote myself:

function NewCookie(const Name, Value, Domain, Path: string; Expires: TDateTime): TAdvWebBrowserCookie;
begin
  Result.Name := Name;
  Result.Value := Value;
  Result.Domain := Domain;
  Result.Path := Path;
  Result.Expires := Expires;
end;

I was not able to reproduce this on my machine.
Can you check if it works for you with the accompanied demo in the AdvWebBrowser Cookies folder?