WIndows succeeding, Android failing second attempts to connect with Server Certificate Invalid or not present error

Viewed 194

Using C++Builder, I need to create a small app that gets some info from a PHP file on a remote site.

I have a TRESTClient, TRESTRequest and TRESTResponse that are properly setup.

Compiled under Windows 32-bit, I can repeatedly execute the function below and get data back.

However, compiled for Android 32-bit, the code below works ONLY the first time, returning data from the server. Any subsequent button clicks to reenter the function causes a generated error:

Server Certificate Invalid or not present

There is a related post at Server certificate Invalid or Not present, but it is of no help.

So, on Windows, this simple code works fine, again and again, but works only once on Android before failing.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    RESTRequest1->Resource = "";
    RESTRequest1->Method = TRESTRequestMethod::rmPOST;
    RESTRequest1->Response = RESTResponse1;
    RESTRequest1->Response->ContentType = "application/json";
    RESTRequest1->Response->ContentEncoding="UTF-8";
    RESTRequest1->Execute();
    
    Memo1->Lines->Add(RESTResponse1->Content);

Not sure how to get around this error.

1 Answers

I have ran into the same problem. I was able to work around it by creating a new TRestClient object dynamically each time that I need to do a request and assign the client of that request to the newly created TRestClient object.

Related