HTTP Server in CBuilder - delphi

I am a new user in CBuilder Programming. I am writing HTTP Server application, which receives mixed data:both text and a binary data at a time. But I don't know which component and how to use to parse incoming request. My aim is to separate a text data from binary one. Can anybody show examples in Cbuilder or Delphi?

Try using indy, check the TIdHTTPServer component and the OnCommandGet event to process the GET, POST, and HEAD requests.

Related

Indy10 Readln and ByteEncoding

I would like to use AContext.Connection.IOHandler.ReadLn in Indy10 on my IdTcpServer but I don't know how to use the ByteEncoding Parameter. Does the client have to send a WideString or AnsiString?
If you are in control of both the client and server code, then you decide what specific encoding the client sends the text as (UTF-8 is a good choice), and then code the server accordingly. Indy defaults to ASCII, but you can change that. However, if you are not in control of the client code, then you need to find out what encoding the client is actually using so that you can then code the server accordingly. Don't just make blind assumptions. Find out what is actually being used.

How do I retrieve a complete HTTP response from a web server including response body using an Indy TIdTCPClient instance?

I have a Delphi 6 application that uses an Indy TIdTCPClient instance to communicate with a web server. The reason I am not using an HTTP client directly is because the the server is an image streaming server that uses the same socket connection for receiving the command to start streaming as it does to start "pushing" images back to you. In other words, after you send it a typical HTTP POST request, it replies with an HTTP response, and immediately after that it starts sending out a stream of JPEG images.
I already know how to craft a proper POST request and send it using the TIdTCPClient WriteBuffer() method and then use the ReadBuffer() method to receive reply data. What I'd like to do instead is to send a POST request and then ask Indy to wait for a typical HTTP response including retrieving all the bytes in the response body if there is a Content-Length header variable. I of course want it to leave the JPEG frames intact that may have piled in after the HTTP response in the receive queue until I start requesting them (that is, I don't want it including any of the JPEG frames in the HTTP response to my streaming request command until I ask for them using a successive read call).
Is there a method that I can call on a TIdTCPClient that will retrieve completely a typical HTTP response with body content, and nothing else? I thought about using SendCmd() and checking the LastCmdResult property (type: TIdRFCReply) for the response, but I can't tell from the Indy documentation if it retrieves the response body content too if there is a Content-Length header variable as part of the response it returns, nor can I tell if it leaves the rest of the receive queue after the response intact.
What is the best way to accomplish this mixed mode interaction with an HTTP web server that pushes out a stream of JPEG frames right after you make the HTTP request to start streaming?
Also, if there is a clever way to have Indy split the frames using the JPEG frame WINBONDBOUDARY delimiting string, rather than accumulating blocks of data and parsing them out myself, please share that technique.
The correct way to read an HTTP response is to first read the CRLF-delimited response headers line-by-line until a blank line is encountered, aka a CRLF+CRLF sequence, then you can use those headers to decide how to read the remaining response data. The headers will tell you not only what kind of stream is being sent (via the Content-Type header), but also how the data is being framed (Content-Length, Transfer-Encoding: chunked, something specific to the particular Content-Type, etc).
To receive the headers, you can use the connection's Capture() method, setting its ADelim parameter to a blank string.
How you read the remaining data afterwards depends on the actual formatting/framing of the stream. Without knowing exactly what kind of stream you are receiving, there is no way to advise you how best to read it, as there are several different types of streaming protocols used by HTTP servers, and most of them are not standardized. Provide that information, then I/we can show you how to implement it with Indy.
You cannot use SendCmd() as the HTTP protocol does not format its responses in a way that is compatible with that method.

simple WSDL wrapper for HTTP process?

Suppose I have a simple HTTP form that uses POST to pass some parameters
and returns OK or BAD (which I do). A client wants this to be published
as a WSDL description. Looking into WSDL I see an infinite morass of
formalisms, but no practical tools.
Surely there must be a simple way to create a wrapper for a simple form processor?
When you do a POST of the form data, do you use HTML to send the users data? If yes then you have to change both client and server. The idea you encapsulate the form's data in a SOAP envelope and send it over HTTP. So I am not sure what you mean by
a wrapper for a simple form processor

Progress feedback in stateless HTTP session

I need to program a stateless server to execute remote methods. The client uses REST with a JSON parameter to pass the method name and its parameters. After servicing the result the session is closed. I have to use Indy10, TCP/IP as protocol, and therefore look at using IdHTTPServer.
Large result sets are chunked by Indy10 and sent to the client in parts.
My problem now is:
The methods on the server provide progress information if they take longer to produce the results. These are short messages. How can I write back to the client?
So far I have used writeflush on the server, but the client waited for the request to end before handing back the full resultset, including the progress information. What can I do to display/process such progress information on the client and yet keep the connection open to receive further data on the same request?
On the client side instead of the regular HTTP client component TIdHTTP you can instead use Indy class TIdTCPClientCustom in unit IdTCPClient to send the request and process the response.
This class gives total control over the processing of the server responses. I used the TIdTelnet class as a starting point to implement a client for a message broker messaging protocol, and found it stable and reliable for both text and binary data.
In the receiving thread, the incoming data can be read up to delimiters and parsed into chunks (for the progress information) and immediately processed.

How can I access/modify headers of request/reponses in a Delphi 2010 DataSnap Server

I'm in the process of building a DataSnap Server that functions as WebDAV server and I'm trying to read the request headers when using a DSHTTPService and then modify the response headers.
Can anyone point me in the right direction? I've notice the Trace TDSRequest and TDSResponse are ancestors of TDSRequestIndy and TDSResponseIndy and those components have access to the headers but am not entirely sure how to get from a TDSRequest to TDSRequestIndy.
Also I didn't think that the Trace would be the cleanest way to access the request and response, but it's the only way I've found so far.
The reason for trying to do this with DataSnap and not just straight Indy is that I'm looking to use DataSnap for other remote methods.
Maybe you should consider using TidHTTPServer and create an indy server that has many events and methods, rather than starting from DSHTTPService, including OnBeforeBind, OnAfterBind, OnHeadersAvailable... in which you have access to headers

Resources