简体   繁体   中英

Delphi - Using Indy HTTP Client to send a response back to a server

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

Their system then continues to send unsolicited XML data at regular intervals until a predetermined timeout period expires.

However, the customer now wants my client application to send them a HTTP response back every time I receive data (the response based on successful parsing of the XML).

I can work out how to send a response if I was the server, but how can I generate a response header and use my idHTTP1 client to post (or put, send etc) just the header.

This is I think, not exactly defined in RFC 2616, as the server normally sends the HTTP response, not the client, viz:

6 Response

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

I thought I could use TIdHTTPResponseInfo and use the WriteHeader method, but could not work out how to set up the linkage to the URL I need to reply to if I am the client.

I am using Delphi XE and Indy 10.5.7

I've tried a number of ways, but none of them successfully.

Any help or possible code examples are really appreciated!

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

While sending the data stream until connection is closed corresponds to HTTP standard, HTTP is a request-response protocol. If the client receives data as a response, then it can't reply with it's own response - the client can only send another request. So your task is to figure out, what kind of request the server would accept as a confirmation of data receipt. Once you figure this, you will be able to find how (if) it is possible with IdHTTP.

Update: If you should send 200 OK to the server , then, this is not conformant to HTTP protocol specification. You can try getting to the socket behind the HTTP client and just send 7 bytes (200 OK + CRLF).

If the server expects the client to send an acknowledgement of each XML reply, then the server IS NOT implementing the actual HTTP protocol, as this is not allowed behavior. More likely, they are implementing their own custom protocol that mimics, but is not, HTTP. SIP, for example, has many characterics that are similar to HTTP, and many that are not (multiple replies to single requests, for instance).

You need to find out what kind of the protocol the server is really implementing. You will not be able to use TIdHTTP for it. Use TIdTCPClient directly instead. Then you can send and receive data however you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM