Forum > Networking and Web Programming
GetURLText
Thaddy:
If simpleget won't work, do it like this (also simple, but slightly more involved):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}uses classes,sysutils,fphttpclient,opensslsockets,fpJson,jsonparser; var Client:TFpHttpClient; List:TStringList; URL:String = 'https://www.example.com';begin Client := TfpHttpClient.Create(nil); try // this is important Client.AllowRedirect := true; // I am not sure SimpleGet handles redirects. // optional browser impersonation. This is sometimes necessary, although there is a very old default. Client.RequestHeaders.Add('User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0'); List := TStringlist.Create; try List.Text := Client.Get(URL); writeln(List.Text); finally List.Free; end; finally Client.Free; end;end.
I recommend using fcl-web like above, instead of Synapse. Better maintained and standard.
Warfley:
Just use TFPHTTPClient with the openssl handler:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses opensslsockets, // Include per uses to enable OpenSSL handling fphttpclient; var WebsiteText: String;begin WebsiteText := TFPHTTPClient.SimpleGet('https://my.https.example.com'); WriteLn(WebsiteText);end.OpenSSL is pre installed on windows since a few years, and should also be available on mac and pretty much all of the most common linux distros.
Thaddy:
@Warfley
SimpleGet does not always work, hence my example.
VTwin:
Thanks all. Trying Warfley and Thaddy's examples, I get (on Windows) exception 'EInOutError' "Could not initialize OpenSSL library" in both cases.
I did not try KodeZwerg's example as HTTPSend was not found.
In the distant past I was using Synapse, but switched to fphttpclient to minimize dependencies. It was working fine for a long time, but recently I got a compiler message to include opensslsockets. Now I am getting exceptions.
Thaddy:
64 bit or 32 bit?
The openssl libraries must match exactly.
For now I think there is your problem.
If that is the case it is easy to solve.
(assuming windows64)
Wait for it:
- if it is 32 bit, download the 32 bit version and copy the dll's to \windows\syswow64 (yes 32 bit goes there!)(Many wtf's here)
- if it is 64 bit on 64 bit windows, download the 64 bit version and put the dll's in \windows\system32 (yes 64 bit goes there)(Many wtf's here)
I know this is counter-intuitive..... Let's call it "Windows Logic".
"Surprised? You won't be, until the next episode of Soap"
https://www.youtube.com/watch?v=0BHQT3Omqtw
btw: WoW stands for Windows32 on Windows64. On Linux it would be multi-arch.
Microsoft's answer (ad verbatim):
"The Windows/SysWOW64 directory contains 32-bit libraries and executables while the Windows/System32 directory contains 64-bit libraries and executables. The SysWOW64 directory was created to facilitate the running of 32-bit legacy applications on 64-bit Windows systems."
Many people, even on this forum, get it wrong all the time...... %) %) %) %)
But that is obvious, isn't it? Everyone understands that? :o :D ;)
Navigation
[0] Message Index
[#] Next page
[*] Previous page