Android Question How to flag 404 "page not found" ? [solved]

trepdas

Active Member
Licensed User
Longtime User
Hello good people,

I need to get a boolean true or false for page 404 (page not found) . (such as http://nonexistingdomain.com/342.html)

what would be the best method to do this?

I am trying to use the example here with no success :

when I call the check_http sub and go step by step in debugger mode, it seems that it skips the Sub JobDone completely.

B4X:
Sub check_http
    
    Dim job1 As HttpJob
    job1.Initialize("Job1", Me)
'    'Send a GET request
    job1.Download(WebAddress)
End Sub
'
Sub JobDone (job As HttpJob)
    Log("JobName = " & job.JobName & ", Success = " & job.Success)
    If job.Success = False Then
        Log("Error: " & job.ErrorMessage)
        'do something else
        Msgbox ("error.","")
    
    Else
        Log(job.GetString)
        'do something if ok
    
        WebView1.LoadUrl(WebAddress)
    End If
    job.Release
End Sub





help as usual will be very appreciated.
 

trepdas

Active Member
Licensed User
Longtime User
Hello again. could you check why it is still not responding?

the code is in BtnCheckTag_Click

?


B4X:
Private Sub BtnCheckTag_Click


    
    TmpStr=txtPUTag.Text
    LN=TmpStr.Length
    If LN<4 Then Return
    
    TtgString=TmpStr
    ReplaceSpaces
    CreateIDN
    
        WebUrl=InHttp
    Wait For (CheckHttp(WebUrl)) complete (flag As Boolean)
    ' is it 404 ??
    Log ("why this line is not being executed?")

    
End Sub


Sub CheckHttp (url As String) As ResumableSub
    Dim job As HttpJob
    job.Initialize("", Me)
    job.Download(url)
    Wait For (job) JobDone(job As HttpJob)

    If job.Success Then
        Log(job.GetString)
    Else
        Log(job.errorMessage):' your error should be here
    End If
    job.Release
    Return job.Success
End Sub
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I have just compiled your project and this is what I see in the log.

Logger connected to: Google Pixel 2 XL
--------- beginning of main
Copying updated assets files (3)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
hello_there
hello_there
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: java.net.UnknownServiceException: CLEARTEXT communication to teletag.org not permitted by network security policy, Response:
java.net.UnknownServiceException: CLEARTEXT communication to teletag.org not permitted by network security policy
why this line is not being executed?

So it appears to be working as expected.

I then added

CreateResourceFromFile(Macro, Core.NetworkClearText)

to the manifest and the log showed:

Logger connected to: Google Pixel 2 XL
--------- beginning of main
Copying updated assets files (3)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
hello_there
hello_there
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: java.net.UnknownServiceException: CLEARTEXT communication to teletag.org not permitted by network security policy, Response:
java.net.UnknownServiceException: CLEARTEXT communication to teletag.org not permitted by network security policy
why this line is not being executed?
** Activity (main) Pause, UserClosed = false **
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
try_in_clear
try_in_clear
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: Not Found, Response: <!doctype html>

<html lang="en-US" >

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Page not found &#8211; TeleTag</title>
<meta name='robots' content='noindex,nofollow' />
<link rel='dns-prefetch' href='//s.w.org' />
<link rel="alternate" type="application/rss+xml" title="TeleTag &raquo; Feed" href="https://teletag.org/feed/" />
<link rel="alternate" type="application/rss+xml" title="TeleTag &raquo; Comments Feed" href="https://teletag.org/comments/feed/" />
<script>
window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/teletag.org\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.6"}};
!function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,8205,55356,57212],[55357,56424,8203,55356,57212])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defer=t.type="text/javascript",a.getElementsByTagName("head")[0].appendChild(t)}for(i=Array("flag","emoji"),t.supports={everything:!0,everythingExceptFlag:!0},o=0;o<i.length;o++)t.supports[i[o]]=l(i[o]),t.supports.everything=t.supports.everything&&t.supports[i[o]],"flag"!==i[o]&&(t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&t.supports[i[o]]);t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&!t.supports.flag,t.DOMReady=!1,t.readyCallback=function(){t.DOMReady=!0},t.supports.everything||(n=function(){t.readyCallback()},a.addEventListener?(a.addEventListener("DOMContentLoaded",n,!1),e.addEventListener("load",n,!1)):(e.attachEvent("onload",n),a.attachEvent("onreadystatechange",function(){"complete"===a.readyState&&t.readyCallback()})),(r=t.source||{}).concatemoji?d(r.concatemoji):r.wpemoji&&r.twemoji&&(d(r.twemoji),d(r.wpemoji)))}(window,document,window._wpemojiSettings);
</script>
<style>
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 .07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}
</style>
<link rel='stylesheet' id='wp-block-library-css' href='http://teletag.org/wp-includes/css/dist/block-library/style.min.css?ver=5.6' media='all' />
<link rel='stylesheet' id='wp-block-library-theme-css' href='http://teletag.org/wp-includes/css/dist/block-library/theme.min.css?ver=5.6' media='all' />
<link rel='stylesheet' id='twenty-twenty-one-style-css' href='http://teletag.org/wp-content/themes/twentytwentyone/style.css?ver=1.1' media='all' />
<link rel='stylesheet' id='twenty-twenty-one-print-style-css' href='http://teletag.org/wp-content/themes/twentytwentyone/assets/css/print.css?ver=1.1' media='print' />
<link rel="https://api.w.org/" href="https://teletag.org/wp-json/" /><link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://teletag.org/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://teletag.org/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 5.6" />
<style>.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style></head>



<body class="error404 wp-embed-responsive is-light-theme no-js hfeed">

<div id="page" class="site">

<a class="skip-link screen-reader-text" href="#content">Skip to content</a>





<header id="masthead" class="site-header has-title-and-tagline" role="banner">







<div class="site-branding">





<p class="site-title"><a href="https://teletag.org/">TeleTag</a></p>



<p class="site-description">

Tag The Net ! </p>

</div><!-- .site-branding -->




</header><!-- #masthead -->



<div id="content" class="site-content">

<div id="primary" class="content-area">

<main id="main" class="site-main" role="main">

<header class="page-header alignwide">
<h1 class="page-title">Available Tag</h1>
</header><!-- .page-header -->
<div class="error-404 not-found default-max-width">
<div class="page-content">
<p>It looks like you have used a tag that is available for use</p>
<form role="search" method="get" class="search-form" action="https://teletag.org/">

<label for="search-form-1">Search&hellip;</label>

<input type="search" id="search-form-1" class="search-field" value="" name="s" />

<input type="submit" class="search-submit" value="Search" />

</form>

</div><!-- .page-content -->
</div><!-- .error-404 -->
</main><!-- #main -->

</div><!-- #primary -->

</div><!-- #content -->





<aside class="widget-area">

<section id="search-2" class="widget widget_search"><form role="search" method="get" class="search-form" action="https://teletag.org/">

<label for="search-form-2">Search&hellip;</label>

<input type="search" id="search-form-2" class="search-field" value="" name="s" />

<input type="submit" class="search-submit" value="Search" />

</form>

</section>
<section id="recent-posts-2" class="widget widget_recent_entries">
<h2 class="widget-title">Recent Posts</h2><nav role="navigation" aria-label="Recent Posts">
<ul>
<li>
<a href="https://teletag.org/2021/01/16/hello-world/">Hello world!</a>
</li>
</ul>
</nav></section><section id="recent-comments-2" class="widget widget_recent_comments"><h2 class="widget-title">Recent Comments</h2><nav role="navigation" aria-label="Recent Comments"><ul id="recentcomments"><li class="recentcomments"><span class="comment-author-link"><a href='https://wordpress.org/' rel='external nofollow ugc' class='url'>A WordPress Commenter</a></span> on <a href="https://teletag.org/2021/01/16/hello-world/#comment-1">Hello world!</a></li></ul></nav></section> </aside><!-- .widget-area -->





<footer id="colophon" class="site-footer" role="contentinfo">



<div class="site-info">

<div class="site-name">

<a href="https://teletag.org/">TeleTag</a>

</div><!-- .site-name -->

<div class="powered-by">

Proudly powered by <a href="https://wordpress.org/">WordPress</a>. </div><!-- .powered-by -->



</div><!-- .site-info -->

</footer><!-- #colophon -->



</div><!-- #page -->



<script>document.body.classList.remove("no-js");</script> <script>

if ( -1 !== navigator.userAgent.indexOf( 'MSIE' ) || -1 !== navigator.appVersion.indexOf( 'Trident/' ) ) {

document.body.classList.add( 'is-IE' );

}

</script>

<script id='twenty-twenty-one-ie11-polyfills-js-after'>
( Element.prototype.matches && Element.prototype.closest && window.NodeList && NodeList.prototype.forEach ) || document.write( '<script src="http://teletag.org/wp-content/themes/twentytwentyone/assets/js/polyfills.js?ver=1.1"></scr' + 'ipt>' );
</script>
<script src='http://teletag.org/wp-content/themes/twentytwentyone/assets/js/responsive-embeds.js?ver=1.1' id='twenty-twenty-one-responsive-embeds-script-js'></script>
<script src='http://teletag.org/wp-includes/js/wp-embed.min.js?ver=5.6' id='wp-embed-js'></script>
<script>

/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",(function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())}),!1);

</script>



</body>

</html>

<!--Generated by Endurance Page Cache-->
Message longer than Log limit (4000). Message was truncated.
<!doctype html>

<html lang="en-US" >

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Page not found &#8211; TeleTag</title>
<meta name='robots' content='noindex,nofollow' />
<link rel='dns-prefetch' href='//s.w.org' />
<link rel="alternate" type="application/rss+xml" title="TeleTag &raquo; Feed" href="https://teletag.org/feed/" />
<link rel="alternate" type="application/rss+xml" title="TeleTag &raquo; Comments Feed" href="https://teletag.org/comments/feed/" />
<script>
window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/teletag.org\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.6"}};
!function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,8205,55356,57212],[55357,56424,8203,55356,57212])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defer=t.type="text/javascript",a.getElementsByTagName("head")[0].appendChild(t)}for(i=Array("flag","emoji"),t.supports={everything:!0,everythingExceptFlag:!0},o=0;o<i.length;o++)t.supports[i[o]]=l(i[o]),t.supports.everything=t.supports.everything&&t.supports[i[o]],"flag"!==i[o]&&(t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&t.supports[i[o]]);t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&!t.supports.flag,t.DOMReady=!1,t.readyCallback=function(){t.DOMReady=!0},t.supports.everything||(n=function(){t.readyCallback()},a.addEventListener?(a.addEventListener("DOMContentLoaded",n,!1),e.addEventListener("load",n,!1)):(e.attachEvent("onload",n),a.attachEvent("onreadystatechange",function(){"complete"===a.readyState&&t.readyCallback()})),(r=t.source||{}).concatemoji?d(r.concatemoji):r.wpemoji&&r.twemoji&&(d(r.twemoji),d(r.wpemoji)))}(window,document,window._wpemojiSettings);
</script>
<style>
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 .07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}
</style>
<link rel='stylesheet' id='wp-block-library-css' href='http://teletag.org/wp-includes/css/dist/block-library/style.min.css?ver=5.6' media='all' />
<link rel='stylesheet' id='wp-block-library-theme-css' href='http://teletag.org/wp-includes/css/dist/block-library/theme.min.css?ver=5.6' media='all' />
<link rel='stylesheet' id='twenty-twenty-one-style-css' href='http://teletag.org/wp-content/themes/twentytwentyone/style.css?ver=1.1' media='all' />
<link rel='stylesheet' id='twenty-twenty-one-print-style-css' href='http://teletag.org/wp-content/themes/twentytwentyone/assets/css/print.css?ver=1.1' media='print' />
<link rel="https://api.w.org/" href="https://teletag.org/wp-json/" /><link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://teletag.org/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://teletag.org/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 5.6" />
<style>.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style></head>



<body class="error404 wp-embed-responsive is-light-theme no-js hfeed">

<div id="page" class="site">

<a class="skip-link screen-reader-text" href="#content">Skip to content</a>





<header id="masthead" class="site-header has-title-and-tagline" role="banner">







<div class="site-branding">





<p class="site-title"><a href="https://teletag.org/">TeleTag</a></p>



<p class="site-description">

Tag The Net ! </p>

</div><!-- .site-branding -->




</header><!-- #masthead -->



<div id="content" class="site-content">

<div id="primary" class="content-area">

<main id="main" class="site-main" role="main">

<header class="page-header alignwide">
<h1 class="page-title">Available Tag</h1>
</header><!-- .page-header -->
<div class="error-404 not-found default-max-width">
<div class="page-content">
<p>It looks like you have used a tag that is available for use</p>
<form role="search" method="get" class="search-form" action="https://teletag.org/">

<label for="search-form-1">Search&hellip;</label>

<input type="search" id="search-form-1" class="search-field" value="" name="s" />

<input type="submit" class="search-submit" value="Search" />

</form>

</div><!-- .page-content -->
</div><!-- .error-404 -->
</main><!-- #main -->

</div><!-- #primary -->

</div><!-- #content -->





<aside class="widget-area">

<section id="search-2" class="widget widget_search"><form role="search" method="get" class="search-form" action="https://teletag.org/">

<label for="search-form-2">Search&hellip;</label>

<input type="search" id="search-form-2" class="search-field" value="" name="s" />

<input type="submit" class="search-submit" value="Search" />

</form>

</section>
<section id="recent-posts-2" class="widget widget_recent_entries">
<h2 class="widget-title">Recent Posts</h2><nav role="navigation" aria-label="Recent Posts">
<ul>
<li>
<a href="https://teletag.org/2021/01/16/hello-world/">Hello world!</a>
</li>
</ul>
</nav></section><section id="recent-comments-2" class="widget widget_recent_comments"><h2 class="widget-title">Recent Comments</h2><nav role="navigation" aria-label="Recent Comments"><ul id="recentcomments"><li class="recentcomments"><span class="comment-author-link"><a href='https://wordpress.org/' rel='external nofollow ugc' class='url'>A WordPress Commenter</a></span> on <a href="https://teletag.org/2021/01/16/hello-world/#comment-1">Hello world!</a></li></ul></nav></section> </aside><!-- .widget-area -->





<footer id="colophon" class="site-footer" role="contentinfo">



<div class="site-info">

<div class="site-name">

<a href="https://teletag.org/">TeleTag</a>

</div><!-- .site-name -->

<div class="powered-by">

Proudly powered by <a href="https://wordpress.org/">WordPress</a>. </div><!-- .powered-by -->



</div><!-- .site-info -->

</footer><!-- #colophon -->



</div><!-- #page -->



<script>document.body.classList.remove("no-js");</script> <script>

if ( -1 !== navigator.userAgent.indexOf( 'MSIE' ) || -1 !== navigator.appVersion.indexOf( 'Trident/' ) ) {

document.body.classList.add( 'is-IE' );

}

</script>

<script id='twenty-twenty-one-ie11-polyfills-js-after'>
( Element.prototype.matches && Element.prototype.closest && window.NodeList && NodeList.prototype.forEach ) || document.write( '<script src="http://teletag.org/wp-content/themes/twentytwentyone/assets/js/polyfills.js?ver=1.1"></scr' + 'ipt>' );
</script>
<script src='http://teletag.org/wp-content/themes/twentytwentyone/assets/js/responsive-embeds.js?ver=1.1' id='twenty-twenty-one-responsive-embeds-script-js'></script>
<script src='http://teletag.org/wp-includes/js/wp-embed.min.js?ver=5.6' id='wp-embed-js'></script>
<script>

/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",(function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())}),!1);

</script>



</body>

</html>

<!--Generated by Endurance Page Cache-->
Message longer than Log limit (4000). Message was truncated.
why this line is not being executed?
** Activity (main) Pause, UserClosed = false **

Not sure why it is not working for you.
 
Upvote 0
Top