p-samuel
Members-
Content Count
7 -
Joined
-
Last visited
-
Days Won
1
Everything posted by p-samuel
-
Parse Json again, complicated
p-samuel replied to direktor05's topic in RTL and Delphi Object Pascal
Do you know about https://jsontodelphi.com/ website? If you are in a hurry then go there generate your classes dto's. Copy and past your json string and they will generate a dto boilerplate for you. The only problem is that this boilerplate uses generics and cannot be implemented in old versions of Delphi. Otherwise, check out Super Object in github project that is aimed for these cases. -
Subscribe to a web stream and listen to incoming streams
p-samuel posted a topic in Network, Cloud and Web
I have an url where I can listen to incoming streams whenever a new notification is published. It works perfectly using the cmd curl command but I can't reproduce the same in delphi. I tried using CreateProcess and read the output stream of the process but was worthless. Some has any idea how to make this? curl -s ntfy.sh/something-very-strange/json Each line is a response from the server. When a "GET" request is sent it opens a connection pool and doesn't closes it, sending packages streams to the subscriber, just like a web-socket, until the subscriber ends the process. My goal is to be able to connect and subscribe to this url through delphi, maybe using some component, process or any other tool which allows me to do so. -
Subscribe to a web stream and listen to incoming streams
p-samuel replied to p-samuel's topic in Network, Cloud and Web
@Remy Lebeau, debugging is quite simple using chrome's dev tools. As you have said before, it seems a better option using TIdEventStream as the data itself is transmitted by events, like a websocket. It's a plug and play. I didn't know Indy was so easy to setup this. type TNotityProviderIndy = class private FIOHandlerSSL: TIdSSLIOHandlerSocketOpenSSL; FIdHTTP: TIdHTTP; FIdEventStream: TIdEventStream; procedure OnWriteEvent(const ABuffer: TIdBytes; AOffset, ACount: Longint; var VResult: Longint); public constructor Create; end; implementation { TNotityProviderIndy } constructor TNotityProviderIndy.Create; begin FIdHTTP := TIdHTTP.Create(nil); FIOHandlerSSL := TIdSSLIOHandlerSocketOpenSSL.Create; FIdEventStream := TIdEventStream.Create; FIOHandlerSSL.SSLOptions.Method := sslvTLSv1_2; FIdHTTP.IOHandler := FIOHandlerSSL; FIdHTTP.Request.Accept := 'text/event-stream'; FIdHTTP.Request.CacheControl := 'no-store'; FIdHTTP.HTTPOptions := [hoNoReadMultipartMIME, hoNoReadChunked]; FIdEventStream.OnWrite := OnWriteEvent; end; procedure TNotityProviderIndy.OnWriteEvent(const ABuffer: TIdBytes; AOffset, ACount: Longint; var VResult: Longint); begin Writeln(IndyTextEncoding_UTF8.GetString(ABuffer)); end; Thanks for the info! -
Subscribe to a web stream and listen to incoming streams
p-samuel replied to p-samuel's topic in Network, Cloud and Web
@Remy Lebeau, I don't know any other way of debugging subsequent requests and displaying verbose information apart from using -v in curl so far. @Vincent Gsell's answer helped me on giving me a north where should I go, but I'll also try taking a deep look on the information that you shared. I really appreciate the help of you all. Delphi is a quite hard language and documentation concerning these components is quite hard to find. Thank you all guys! -
Subscribe to a web stream and listen to incoming streams
p-samuel replied to p-samuel's topic in Network, Cloud and Web
@Remy Lebeau Here is a snapshot of the response in verbose. I just omitted some sensitive information. -
Subscribe to a web stream and listen to incoming streams
p-samuel replied to p-samuel's topic in Network, Cloud and Web
@Vincent Gsell This worked perfectly! I just needed to make some adjustments but it worked just like a glove! Thanks by heart! -
Subscribe to a web stream and listen to incoming streams
p-samuel replied to p-samuel's topic in Network, Cloud and Web
Hello @Fr0sT.Brutalthanks for your interest. This is not a websocket, it's a http url. I am trying to read the stream of responses when I send a GET request, but I'm afraid this is not possible to be done in Delphi by native components such as RestResquest or Indy: In Python would sound like this: resp = requests.get("https://ntfy.sh/something-very-strange/json", stream=True) for line in resp.iter_lines(): if line: print(line)