TNetHTTPClient.get return an Interface


I try to add TNetHTTPClient in scripter.
Problem TNetHTTPClient.get post, put etc. methods return an IHTTPResponse (=Interface).

Using SCripter studio import tool I try to handle with RTTi and it's doesn't work. Without RTTI Scripter Studio ignore all method with interface argument or return value.
So I try to handle it manually to return a THTTPResponse => Failed too

How to handle TNetHTTPClient with scripter ?

Full sample in attachment.

Tested on Delphi 11/12 + VCL + Win32 (7,6 Ko)

Unfortunately interfaces are indeed not supported by TMS Scripter.

Hello Wagner,

I know this.
That's why I tried to cast it as a THTTPResponse :

ReturnOutputArg(  ObjectToVar(THTTPResponse(AResult as THTTPResponse)));

And with :

  with Scripter.DefineClassByRTTI(TNetHTTPClient) do
    DefineMethod('Get',3,tkClass,THTTPResponse,__TNetHTTPClientGet,false,2,'AURL:string;const AResponseContent:TStream=nil;AHeaders:TNetHeaders=nil');

But where is my mistake ?

You didn't explain the exact problem you are having with your approach, but my guess is that this won't work because under the hood the Delphi HTTP client component is still dealing with the interface.

Once the interface reference count reaches zero, the object will be destroyed. So I believe you are having some Access Violation error?

I have this error :

The Project5.exe project triggered the exception class ENetHTTPException with the message 'Header query error: (6) Invalid descriptor'.

in this SCripter line :

if THTTPResponse(HttpResponse).getStatusCode = 200 then   

But I have tried with :

  TatNet_HttpClientComponentLibrary = class(TatScripterLibrary)
    procedure Init; override;
    class function LibraryName: string; override;


procedure TatNet_HttpClientComponentLibrary.__TNetHTTPClientGet(AMachine: TatVirtualMachine);
  with AMachine do
    case inputargcount of
    1:FResultCast :=TNetHTTPClient(CurrentObject).get(GetInputArgasString(0)) as THTTPResponse;
    2:FResultCast :=TNetHTTPClient(CurrentObject).get(GetInputArgasString(0),TStream(GetInputArgAsObject(1))) as THTTPResponse;
    3:FResultCast :=TNetHTTPClient(CurrentObject).get(GetInputArgasString(0),TStream(GetInputArgAsObject(1)),TNetHeaders(GetInputArgAsObject(2))) as THTTPResponse;


Same problem !

Probably due to the reason I have already explained in a previous post.