03-21-2023, 10:16 PM
(This post was last modified: 03-21-2023, 10:22 PM by Alexandre Machado.)
Are you referring to the PostDataDemo?
If that's the case, IW will always receive the content as a "file" (from the class THttpFile, declared in IW.HTTP.FileItem.pas), doesn't matter how big is the content that is being received and how it is actually sent from the browser.
So, this code should work for you the same way, considering a TContentJson class:
If you want to use IW built in classes to deal with the Json object as well (which I recommend), you can do something like this:
The library used here (IWJsonDataObjects) is actually JsonDataObjects created by Andreas Hausladen (https://github.com/ahausladen/JsonDataObjects), possibly the best Delphi library to deal with Json objects (and also the fastest).
Remember that you need to register the expected content-type otherwise IW will discard it (because IW won't receive and process unknown content types, unless you explicitly instruct it to do so). In your server controller, do this:
If that's the case, IW will always receive the content as a "file" (from the class THttpFile, declared in IW.HTTP.FileItem.pas), doesn't matter how big is the content that is being received and how it is actually sent from the browser.
So, this code should work for you the same way, considering a TContentJson class:
Code:
function TContentJson.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;
aParams: TStrings): boolean;
var
json: string;
begin
if aRequest.Files.Count = 1 then begin
json:= THttpFile(aRequest.Files[0]).ReadAllText; // <- here you have the whole Json sent to your application as a string
end;
end;
If you want to use IW built in classes to deal with the Json object as well (which I recommend), you can do something like this:
Code:
uses
IWJsonDataObjects;
function TContentJson.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;
aParams: TStrings): boolean;
var
jsonString: string;
jsonObject: TJsonObject;
begin
if aRequest.Files.Count = 1 then begin
jsonString:= THttpFile(aRequest.Files[0]).ReadAllText;
jsonObject := TJsonObject.Parse(jsonString) as TJsonObject; // <- here you have a fully functional json object and you can use TJsonObjects methods and properties
end;
end;
The library used here (IWJsonDataObjects) is actually JsonDataObjects created by Andreas Hausladen (https://github.com/ahausladen/JsonDataObjects), possibly the best Delphi library to deal with Json objects (and also the fastest).
Remember that you need to register the expected content-type otherwise IW will discard it (because IW won't receive and process unknown content types, unless you explicitly instruct it to do so). In your server controller, do this:
Code:
uses
IW.Parser.Files;
procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
begin
RegisterContentType('application/json');
end;