Recent

Author Topic: Get and post request to URL  (Read 35489 times)

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Get and post request to URL
« Reply #30 on: January 28, 2018, 07:39:27 pm »
@rvk

Yes, looks like the problem is with multi SSL threads at the same time. Is there are no solution for this then my app has no sense, because in the final version it will need to manage many at the same time.  :'( I could design a workaround for the references (i.e. every 2,5 seconds check  one, then another an so on) but next step is add Post Request every second also with HTTPS.

I will check if any library (Synapse maybe?) is able to allow multi-thread SSLs.
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Get and post request to URL
« Reply #31 on: January 28, 2018, 08:06:25 pm »
The link said:
Quote
In OpenSSL 1.0.2 (and earlier), applications had to provide their own integration with locking and threads, as documented in the threads.pod file. This page starts with the following unfortunate text:

OpenSSL can safely be used in multi-threaded applications provided that at least two callback functions are set, …
So you could try if 1.1.0g works out of the box but I'm not sure where to download it (it's not on https://indy.fulgan.com/SSL/)

You could try to build in critical sections (at the moment of communication) or you could try the Synapse library.

Edit: Yes, Critical Sections work in this case but slow down the process. So you might only want to do this with https or use a library that handles it correctly.
« Last Edit: January 28, 2018, 08:14:39 pm by rvk »

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Get and post request to URL
« Reply #32 on: January 28, 2018, 08:20:51 pm »
Using HttpGetText (httpsend) from Synapse did work correctly for me.
Don't forget to include ssl_openssl (with httpsend) in the uses clause.

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Get and post request to URL
« Reply #33 on: January 28, 2018, 08:30:36 pm »
Using HttpGetText (httpsend) from Synapse did work correctly for me.
Don't forget to include ssl_openssl (with httpsend) in the uses clause.

Im trying with synapse but im unable to make it work. Could you post the code that worked for you ?
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Get and post request to URL
« Reply #34 on: January 28, 2018, 08:34:36 pm »
Assuming you have Synapse installed.
Project > Project Inspector
Add > New requirement
Choose laz_synapse (or name of your Synapse package)

Then add the uses clause and change your Read_URL_GET() function.
That's it.

Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. uses httpsend, ssl_openssl;
  4.  
  5. {$R *.lfm}
  6.  
  7. { TForm1 }
  8.  
  9. function Read_URL_GET(url: string): string;
  10. var
  11.   Response: TStringList;
  12. begin
  13.   Result := '';
  14.   Response := TStringList.Create;
  15.   try
  16.     if HttpGetText(URL, Response) then
  17.       Result := Response.Text;
  18.   finally
  19.     Response.Free;
  20.   end;
  21. end;


torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Get and post request to URL
« Reply #35 on: January 28, 2018, 08:54:12 pm »
i have synapse installed and added it to the proyect.
https://imageshack.com/a/img924/2079/a8JHyk.png

I added httpsend & ssl_openssl in uses and replaced the function Read_URL_GET with the one you submited.

But now i have this:
unit1.pas(9,59) Fatal: no puedo encontrar httpsendutilizado por Unit1del Inspector de Proyecto. (English => Can not find httpsend used by Unit1 project inspector)

« Last Edit: January 28, 2018, 08:59:16 pm by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Get and post request to URL
« Reply #36 on: January 28, 2018, 09:01:06 pm »
Maybe httpsend isn't compiled yet.

Choose Package > Open Loaded Package
Choose laz_synapse
(extra step I always do) Add > Add Files From File System and add ssl_openssl.pas
Choose Compile and press the red X for closing the package (you can save it is you added ssl_openssl)

Now the httpsend should be compiled and it should work.
(Otherwise your laz_synapse isn't installed correctly)
« Last Edit: January 28, 2018, 09:02:59 pm by rvk »

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Get and post request to URL
« Reply #37 on: January 28, 2018, 09:16:01 pm »
What a nice tip for next situations like this one! It is working perfect right now!
I will add more functions using https request to see f it continue working properly.

Thanks a lot for your help!

Maybe httpsend isn't compiled yet.

Choose Package > Open Loaded Package
Choose laz_synapse
(extra step I always do) Add > Add Files From File System and add ssl_openssl.pas
Choose Compile and press the red X for closing the package (you can save it is you added ssl_openssl)

Now the httpsend should be compiled and it should work.
(Otherwise your laz_synapse isn't installed correctly)
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Get and post request to URL
« Reply #38 on: January 29, 2018, 06:30:44 pm »
Quote
Also note that calling GetJSON(Read_URL_GET('url')) isn't really wise. When Read_URL_GET fails you don't have the option to catch that before reading an empty string into JSON. It would be wise to first read it into a string and then call GetJSON with that string.

The app is runing, but sometimes it throws an error (Access Violation) which im pretty sure is caused for reading empty string as float values. How i could catch when Read_URL_GET fails to avoid this issues?
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

rvk

  • Hero Member
  • *****
  • Posts: 7045
Re: Get and post request to URL
« Reply #39 on: January 29, 2018, 08:19:07 pm »
How i could catch when Read_URL_GET fails to avoid this issues?
if Read_URL_GET fails the result is empty. Don't feed the empty result to GetJSON().

You already read the result into a string separately. So just check for an empty string and only proceed if the string is not empty. Ultimately you could check if you have valid json before doing GetJSON() because the server could also give something unexpected back.

 

TinyPortal © 2005-2018