Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Mouhamed.

Asked: February 20, 2008 - 3:18 pm UTC

Last updated: February 21, 2008 - 9:52 am UTC

Version: 9.0.2

Viewed 10K+ times! This question is

You Asked

Hi Tom,

I have a fonction to validate URL's.
If the status code returned is different than 200 (utl_http.http_ok) the url is logged in the DB.

SOme URL's are returning the status code 500 (SERVER ERROR 500), but the link is valid since I can see it in my browser.

Is there any other way to check the validity of the URL


Any help will be appreciated.

Thanks

Mouhamed


PLease see below my code:


SET SERVEROUTPUT ON
SET DEFINE OFF
DECLARE 
   l_req utl_http.req;
   l_resp utl_http.resp; 
   is_link_valid Boolean := False;  
   pv_url VARCHAR2(250) := 'http://www.canadapost.ca/splash.asp';
   pv_proxy VARCHAR2(250) := '';


BEGIN

  /* request that exceptions are raised for error Status Codes */
     Utl_Http.Set_Response_Error_Check ( enable => true );

  /* allow testing for exceptions like Utl_Http.Http_Server_Error */
     Utl_Http.Set_Detailed_Excp_Support ( enable => true );
 
     UTL_HTTP.set_proxy (pv_proxy);
     l_req := utl_http.begin_request(pv_url);
     l_resp := utl_http.get_response(l_req);
     If l_resp.status_code = utl_http.HTTP_OK  then
        dbms_output.put_line(pv_url || ' / ' || l_resp.status_code || ' : ' || l_resp.reason_phrase);
     end if;
     utl_http.end_response(l_resp);
     EXCEPTION
  WHEN utl_http.bad_url THEN
             dbms_output.put_line(pv_url || ' 1 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);
 WHEN utl_http.bad_argument THEN
             dbms_output.put_line(pv_url || ' 2 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);
 WHEN utl_http.http_client_error THEN
             dbms_output.put_line(pv_url || ' 3 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);  
 WHEN utl_http.http_server_error THEN
             dbms_output.put_line(pv_url || ' 4 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);
 WHEN utl_http.illegal_call THEN
             dbms_output.put_line(pv_url || ' 5 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);  
 WHEN utl_http.init_failed THEN
             dbms_output.put_line(pv_url || ' 6 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);
 WHEN utl_http.protocol_error THEN
             dbms_output.put_line(pv_url || ' 7 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);  
 WHEN utl_http.request_failed THEN
            dbms_output.put_line(pv_url || ' 8 Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm);
 WHEN OTHERS THEN
     dbms_output.put_line(pv_url || ' OTHER Error Msg  : ' || Utl_Http.get_detailed_sqlcode  || Utl_Http.Get_Detailed_Sqlerrm); 
END;



and Tom said...

All urls are valid - all of them. And you know, even if the URL returns "ok" right now - 5 seconds from now the url could be "invalid"

If the server is returning a 500 - that means that at that moment, the server was unable to satisfy the request. Perhaps it wanted a cookie and was really mad you didn't have it - and the application failed (meaning the URL will never execute without lots more work on your part - to set the cookies and everything else). Maybe it wanted you to have a sessionid, and you didn't.

There could be thousands of reasons why a URL will load in your browser - authentication, cookies, looking for a specific http_agent, looking for a particular setting in the "cgi" environment - whatever.

sorry, there is no simple answer here (but gosh, why why why do people code the when others, I will never understand that, not if I live to 1,000 will I get it)

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Mouhamed Elmasry, February 21, 2008 - 10:00 am UTC

Thanks Tom

More to Explore

Security

All of the vital components for a secure database are covered in the Security guide.