Recent

Author Topic: HTTP Server socket  (Read 1737 times)

berghem

  • Jr. Member
  • **
  • Posts: 57
HTTP Server socket
« on: February 16, 2021, 09:18:25 pm »
Hi All
I need to write an application that receive a POST with simple Json
{"variable1":"Value","Variable2":"Value",....}

I'm using synapse library (but I can change and use another library) but i didn't see any example....

zamronypj

  • Full Member
  • ***
  • Posts: 131
    • Fano Framework, Free Pascal web application framework
Re: HTTP Server socket
« Reply #1 on: February 17, 2021, 12:59:51 am »
I do not know about synapse, but if  you use fpweb, TRequest has OnUnknownEncoding event which will be called when request is handling POST or PUT request but with unknown content type.

Currently fpweb TRequest handles multipart/form-data and application/x-www-form-urlencoded only. So POST with application/json content-type is unknown content type.

However to be able to set OnUnknownEncoding event you need to set it before request body is read and parsed.
Best place to set it I guess would be to override TFPCustomHttpServer.initRequest() method. This method is called after TRequest instance is created but before reading data from socket.
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Apache module executes Pascal program like scripting language https://zamronypj.github.io/mod_pascal/
Github https://github.com/zamronypj

berghem

  • Jr. Member
  • **
  • Posts: 57
Re: HTTP Server socket
« Reply #2 on: February 18, 2021, 09:31:44 pm »
Thanks, I resolved with this Library fpweb, it's very simple with 1 code row

tks

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1021
    • Lebeau Software
Re: HTTP Server socket
« Reply #3 on: February 19, 2021, 05:19:21 pm »
I need to write an application that receive a POST with simple Json
{"variable1":"Value","Variable2":"Value",....}

I'm using synapse library (but I can change and use another library) but i didn't see any example....

Indy has a TIdHTTPServer component.  In its OnCommandGet event (which also handles POSTs), you can access the JSON data via the provided ARequestInfo parameter, in its PostStream property.
« Last Edit: August 09, 2021, 01:42:11 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

BSaidus

  • Sr. Member
  • ****
  • Posts: 396
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: HTTP Server socket
« Reply #4 on: August 08, 2021, 11:12:43 pm »
I need to write an application that receive a POST with simple Json
{"variable1":"Value","Variable2":"Value",....}

I'm using synapse library (but I can change and use another library) but i didn't see any example....

Indy has a TIdHTTPServer component.  In its OnCommandGet event (which also handles POSTs), you can access the JSON data via the provided ARequestInfo[/font/ parameter, in its PostStream property.

Yep,
Thanks
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018