ContentHandler and PostData - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: ContentHandler and PostData (/thread-3081.html) |
ContentHandler and PostData - svenheuer - 03-21-2023 Hi, I am struggling to get raw json data via a post to my contenthandler. Code: $.ajax({type: "POST", So how can I fetch the post data in the contenthandler? ContentFields will separate all fields into something like this (mostly) field1=fieldvalue field2=field2value because my json structure is a little bit complexer (contains further objects and arrays) than in the demo this is not the way I can go. I am missing somethling like aRequest.PostData as String or TStream. Is it there but I can not find it? The XML-Example is using uploading a file but that's not the way I go here. Best regards Sven RE: ContentHandler and PostData - Alexandre Machado - 03-21-2023 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: Code: function TContentJson.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; 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 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 RE: ContentHandler and PostData - svenheuer - 03-22-2023 Thank you, Alexandre, I tried it with the "files approach". But -aRequest.Files.Count- is always zero. May be I missed the registration of the contenttype. I will try it with this. Sven RE: ContentHandler and PostData - Alexandre Machado - 03-22-2023 Yes, Sven, without the registration of the type, the number of files will always be zero. IW will just ignore unknown content as a security risk. |