[It is known that only works with D2010]
You can use MSXML to send client requests (add msxml and ole2 to the uses ). The trick is to use IServerXMLHTTPRequest, not IXMLHTTPRequest, since the former allows you to specify timeouts. The code below shows the Execute() method of a thread:
procedure TClientSendThread.Execute; const LResolveTimeoutMilliseconds = 2000; LConnectTimeoutMilliseconds = 5000; LSendTimeoutMilliseconds = 5000; LReceiveTimeoutMilliseconds = 10000; var LHTTPServer: IServerXMLHTTPRequest; LDataStream: TMemoryStream; LData: OleVariant; begin {Needed because this is inside a thread.} CoInitialize(nil); LDataStream := TMemoryStream.Create; try {Populate ....LDataStream...} LData := MemoryStreamToOleVariant(LDataStream); LHTTPServer := CreateOleObject('MSXML2.ServerXMLHTTP.3.0') as IServerXMLHTTPRequest; LHTTPServer.setTimeouts( LResolveTimeoutMilliseconds, LConnectTimeoutMilliseconds, LSendTimeoutMilliseconds, LReceiveTimeoutMilliseconds ); LHTTPServer.open('POST', URL, False, 0, 0); LHTTPServer.send(LData); FAnswer := LHTTPServer.responseText; finally FreeAndNil(LDataStream); CoUninitialize; end; end;
I recently discovered the extremely annoying behavior of this MSXML method, in which GET requests will not be resubmitted if the URL remains unchanged for subsequent submissions; in other words, the client caches GET requests. This does not happen with POST .
Obviously, after the timeout expires, the Execute method terminates and the thread clears.
source share