[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CGI and JSON
[Thread Prev] | [Thread Next]
- Subject: Re: CGI and JSON
- From: Jesus Guardon <ea7dfh@xxxxxxxxxx>
- Date: Wed, 10 Apr 2024 22:12:54 +0200
- To: user@xxxxxxxxxxxxxxxxxxxxxx
El 10/4/24 a las 21:48, Benoît Minisini escribió:
Le 10/04/2024 à 20:47, Jesus Guardon a écrit :Hi allCurrently I'm trying to get running my first web application to build an API Rest Service using JSON to send data back and forth.I am using Request.Post to retrieve the content of a raw Json POST data with "application/json" header mimetype, but I have no idea how to get the raw content in the request.Post function.I know how to do it by sending my data as "x-www-form-urlencoded" and it works, but instead I would like to get the entire body of the post response. That is how other devs do it in other languages and seems to be the standard way to deal with JSON data.When I print CGI.Dump() after my request I can see in the "CONTENT_LENGHT" environment variable the correct lenght of the sent data, but there doesn't seem to be a way to retrieve the actual data.Benoît, would you shed some light over this?By the way, I'm using Postman as a tool for crafting the POST requests and it's really a great tool.https://www.postman.com/downloads/ Thanks in advanceRequest.Post only deals with 'application/x-www-form-urlencoded' and 'multipart/form-data" content type.For other content type (like 'application/json'), you must read it manually from the standard input.So you do something like that: --8<----------------------------------------------------if Request.Method = "POST" And If Request.ContentType = "application/json" ThensData = Read Request.ContentLength MyJsonData = JSON.FromString(sData) ... Endif --8<---------------------------------------------------- Regards,
Wow! Never thought of reading the stream from a Request. Works like a charm, thanks a lot, Benoît!
Best regards -- Jesus Guardon
CGI and JSON | Jesus Guardon <ea7dfh@xxxxxxxxxx> |
Re: CGI and JSON | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |