Delphi - using an Indy HTTP client to send a response to a server

I am using the idyHTTP Indy object to request XML data from the server. After the request is made, the server sends a response, and I can read the response header OK: result: = IdHTTP1.Response.ResponseText;

Then, their system continues to send unsolicited XML data at regular intervals until the specified wait period expires.

However, now the client wants my client application to send them an HTTP response every time I receive data (the answer is based on successful XML parsing).

I can decide how to send the response if I was a server, but how can I generate the response header and use my idHTTP1 client to publish (or send, send, etc.) the header only.

I think this is not exactly defined in RFC 2616, as the server usually sends an HTTP response, not a client, namely:

6 Answer

"After receiving and interpreting the request message, the server responds with an HTTP response message.

I thought I could use TIdHTTPResponseInfo and use the WriteHeader method, but could not determine how to configure the link to the URL that I need to respond to if I am a client.

I am using Delphi XE and Indy 10.5.7

I tried several methods, but none of them were successful.

Any help or possible code examples are really appreciated!

+4
source share
2 answers

Your question can be divided into two parts: (a) what data should I send to the server to notify the server, and (b) how to send this data using IdHTTP.

When a data stream is sent before the connection is closed, it conforms to the HTTP standard, and HTTP is a request-response protocol. If the client receives the data as a response, he cannot respond with his own answer - the client can send only another request. Therefore, your task is to find out which request the server will accept as confirmation of the receipt of data. Once you do this, you will be able to find out how (if) this is possible with IdHTTP.

Update. If you must send 200 OK to the server, this does not meet the HTTP protocol specification. You can try connecting to the socket behind the HTTP client and just send 7 bytes (200 OK + CRLF).

+4
source

If the server expects the client to send an acknowledgment of each XML response, then the server does NOT implement the actual HTTP protocol, as this is prohibited. Most likely, they implement their own protocol, which imitates, but is not HTTP. For example, SIP has many characteristics that are similar to HTTP, and many of them are not (for example, multiple responses to individual requests).

You need to find out which protocol the server really implements. You cannot use TIdHTTP for this. Use TIdTCPClient . Then you can send and receive data, but you need to.

+1
source

Source: https://habr.com/ru/post/1337660/


All Articles