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
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
begin
DefineMethod('Get',3,tkClass,THTTPResponse,__TNetHTTPClientGet,false,2,'AURL:string;const AResponseContent:TStream=nil;AHeaders:TNetHeaders=nil');
end;
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?
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 :
type
TatNet_HttpClientComponentLibrary = class(TatScripterLibrary)
procedure Init; override;
class function LibraryName: string; override;
private
FResultCast:THTTPResponse;
....
procedure TatNet_HttpClientComponentLibrary.__TNetHTTPClientGet(AMachine: TatVirtualMachine);
begin
with AMachine do
begin
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;
end;
end;
end;