Forum > Networking and Web Programming

TFPHTTPClient and Exception

(1/1)

phlr_fr:
Good morning and Happy New year for everybody,

I have some problems with the use of TFPHTTPClient that is why I decided to test it in a test project.

The code in my test project don't do no more than this :



--- 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";}};} ---  try     vlHttpClient := TFPHTTPClient.Create(nil);     vlString     := vlHttpClient.post('http://localhost/testImp/index.php?p0=1&p1=b&p2=c&p3=d');     vlStatusCode := vlHttpClient.ResponseStatusCode;  except           showmessage('Coucou 1');  end;  vlHttpClient.Free;  

I want to test :
1) the site and the page are OK
2) the site exists but the page isn't ok
3) the site doesn't exist
4) there is no internet

1)    vlStatusCode=200, no message, good response
   => OK

2) I modify line 3 like this

--- 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";}};} ---        vlString     := vlHttpClient.post('http://localhost/testImp/blablabla.php?p0=1&p1=b&p2=c&p3=d');   => vlStatusCode=404, no message
   => OK

3) I modify line 3 like this

--- 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";}};} ---    vlString     := vlHttpClient.post('http://blablabla/testImp/index.php?p0=1&p1=b&p2=c&p3=d');   =>   Window 'Debug error notification' : host name resolution for 'blablabla' failed
      Clic on button 'Continue' => 'Coucouc 1' appears

4) I modify line 3 like this

--- 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";}};} ---    vlString     := vlHttpClient.post('http://localhost/testImp/index.php?p0=1&p1=b&p2=c&p3=d');   but I stop the webserver and no Wifi
   =>   Window 'Debug error notification' : Connect to localhost:80 failed
      Clic on button 'Continue' => 'Coucouc 1' appears

I don't understand why the try doesn't catch this exception in case 3 and 4, and how to do to catch it and avoid this exception's window.

Thanks for advance for your responses.

Philippe

Win 7
Lazarus V 1.8.4
Laragon as test webserver

Leledumbo:
EVERY exception will be caught by the debugger BEFORE your except block. Open the attached dialog and add the exception name to the list or simply press continue.

Navigation

[0] Message Index

Go to full version