3
votes

I have some clients that post xml / soap containers. I would like to build a tiny standalone indy web server app, that accepts any request and displays the content of the PostStream in a memo field. Unfortunately I don't know how to decode the PostStream. I get an exception using this code:

ARequestInfo.PostStream.Seek(0, soFromBeginning);
Memo1.Lines.LoadFromStream(ARequestInfo.PostStream);

I am using Delphi7 Enterprise

1

1 Answers

1
votes

Not every request type uses the PostStream property, so you have to check if the PostStream is not nil before you attempt to use it.

Also, TIdHTTPServer is a multi-threaded component. Its events are triggered in worker threads, and it is not safe to access UI components from outside of the main thread, so you need to synchronize with the main thread when accessing the TMemo.

Update: If you need to always have a PostStream available, in older versions of Indy you can use the OnCreatePostStream event to create your own TStream object to use as the PostStream. In those versions, TIdHTTPServer manages PostStream objects that it creates, and sometimes frees them before giving them to you, but user-defined PostStream objects are not freed until after the request is finished being processed by you. However, in recent Indy 10 releases, there is a new OnDoneWithPostStream event that helps control when a PostStream gets freed for any given request, regardless of whether it is created by TIdHTTPServer or by you (in which case, you don't need to use the OnCreatePostStream event to extend the PostStream's lifetime). In all versions, an unfreed PostStream is always freed when the TIdHTTPRequestInfo object is freed.