Hi, good afternoon.
We’ve been trouble while doing a “POST Request” with a JSON Array Object on our RO Server on Delphi.
RO Class: uROJSONParser
RO Method: procedure LoadFromStream(Source: TStream; aUTF8Stream: Boolean = True);
Attachment: Teste RO.zip
Example:
POST REQUEST: http://localhost:8099/api/NewProjectService\teste
Body: [{“test”:“test”}]
Error that we got:
Postman:
HTTP: 500
Invalid Path
Delphi:
First chance exception at $75A90B82. Exception class EROJSONException with message ‘Incompatible datatype’. Process NewProjectServer.exe (13692)
OS: Windows 10
Delphi: 10.2
ROVersion: 10.0.0.1553
PS: We can’t change JSON Format that customer send us.
Thx.
Teste RO.zip (4.4 MB)
EvgenyK
(Evgeny Karpov)
May 23, 2024, 7:09am
2
Hi,
You can use Using OnCustomResponseEvent in a ROSDK Server code snippet and transform some_json_string into {"Param1" : "some_json_string"}
. Later in teste
method you can process this json
Teste RO.zip (29.9 KB)
Hi
Yes, but where could I put this code snippet to be fired in the send of the POST Request?
Because when the POST was made is directly called uRO… classes, after calling the Create Service.
Thx.
EvgenyK
(Evgeny Karpov)
May 23, 2024, 12:00pm
4
Hi,
Have you reviewed my testcase?
add something like ShowMessage(Param1);
into your teste
method
Hi
Right I’ve seen your example.
Is there a way to do programatically? Follow
procedure ROIndyHTTPServer1CustomResponseEvent(const aTransport: IROHTTPTransport; const aRequestStream,
aResponseStream: TStream; const aResponse: IROHTTPResponse; var aHandled: Boolean);
var
s: string;
b: TBytes;
begin
Log.add(‘ROIndyHTTPServer1CustomResponseEvent : test’);
end;
…
…
Result := TROIndyHTTPServer.Create(nil);
(Result as TROIndyHTTPServer).OnCustomResponseEvent := ROIndyHTTPServer1CustomResponseEvent;
…
…
Doing this I got the error:
[dcc32 Error] bServerTest.pas(114): E2009 Incompatible types: ‘method pointer and regular procedure’
EvgenyK
(Evgeny Karpov)
May 23, 2024, 1:42pm
6
Hi,
have you noticed that event is declared as procedure(...) of object
:
TROHTTPGetCustomResponseEvent = procedure(
const aTransport: IROHTTPTransport;
const aRequestStream, aResponseStream: TStream;
const aResponse: IROHTTPResponse;
var aHandled: Boolean) of object;
but you are trying to use it as usual procedure
…
as a result, you have
Hi I’ve fixed the problem but notice this Snippet in the procedure
procedure TROBaseHTTPServer.ProcessRequest(const aTransport: IROHTTPTransportEx;
First it handle the Dispatcher , to after do Something in the CustomResponseEvent.
The error is fired in the Dispatcher Handler when we do the POST Request.
As I said, we receive firstly the JSON with brackets, to process, is not a Response of the server.
EvgenyK
(Evgeny Karpov)
May 23, 2024, 2:43pm
8
Hi,
as designed.
and retest my testcase. it will work as expected
Hi
Ok, We’ll test later in our scenario. May be work slightly different.
Thx anyway.