get webpage content lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- apeoperaio · 2017-12-11 17:06 I am trying to get a webpage content. I used in the past both TFPHTTPClient from fphttpclient and THTTPSend from synapse httpsend. Anyway I have some issues. I am trying to resolve url like: https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/CCNCC/cids I I use TFPHTTPClient I am able to download the url content: urlrequest:= TFPHTTPClient.Create(nil); try inputstr:= 'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/ CCNCC/cids'; urlrequest.SimpleGet(inputstr); finally end; but if the webpage does not exists or if I get some messages I am not able to catch the exceptions (an error is raised by my application even if the request is under try finaly). Using THTTPSend  I am not able to resolve the url: httpClient:= THTTPSend.Create; try     inputstr:= 'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smi les/CCNCC/cids';     getResult:= httpClient.HTTPMethod('GET', inputstr); finally end; getresult is always false, even if the url is correct. What am I doing wrong? ---------------------------------------------------------------------- molly · 2017-12-11 17:29 see this thread for a recent discussion on the subject. ---------------------------------------------------------------------- avra · 2017-12-11 22:39 Quote from: apeoperaio on December 11, 2017, 06:06:36 pman error is raised by my application even if the request is under try finalyTo catch an exception you need try..except not try..finally. For more info take a look at http://www.delphibasics.co.uk/RTL.asp?Name=Finally: QuoteHowever, the Finally clause does not actually handle any exceptions You probably want to combine try..finally as outer scope with try..except as inner scope. Unfortunately there is no single try..except..finally scope yet in FreePascal, which is a little annoying and stays in the way of code readability. ---------------------------------------------------------------------- Leledumbo · 2017-12-12 05:49 You don't always have to use SimpleGet, as it has some predetermined values set, including allowed status code, which is only 200 by default, everything else will raise exception. Set up the properties and parameters yourself and use Get, so you can handle it yourself. Otherwise, what avra suggested should work. ---------------------------------------------------------------------- apeoperaio · 2017-12-12 08:54 Quote from: avra on December 11, 2017, 11:39:08 pmTo catch an exception you need try..except not try..finally. Thanks!