Jump to content
AllanF

Can I respond to a REST Request from TSslWSocketServer

Recommended Posts

I already have a TSslWSocketServer listening on port NNNN and successfully accepts TSSLWSocket client connections. All this happens within the context of my Delphi Applications. Now I need to provide an API in my application. I want to use the existing TSslWSocketServer to listen to any REST calls also. REST call comes in successfully and I can read the content in DataAvailable Event too. My problem is that I cannot send back any message to the REST Client. I am using (Sender as TClientConnection).SendStr('Hi') but it does not reach the REST Client.

I know this is not the appropriate way but I just need to send some indication that message has been received.

Share this post


Link to post

REST client requests are usually sent using HTTPS, this should be obvious where the data you receive from the client contains HTTP headers, so you have to reply using HTTP, your Hi response will simply be ignored by the client. 

 

Ideally, you would be using the web server component, but creating a simple HTTP header and response HTTP page is only a few lines of code.

 

Angus

 

Share this post


Link to post

Hi Angus,

My REST Client request is Secured TLS.

 

Also (Sender as TClientConnection).SendStr('Hi')   wherein

 

Type

  TClientConnection = class(TSSLWSocketClient)

 

It is essential that I use Secured Layer only.

Share this post


Link to post

So this is just a private protocol, not really REST.  Commonly, textual responses are followed by CRLF, that may be what the client is expecting.

 

Angus

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×