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.


So it appears to be working as expected.

I then added

CreateResourceFromFile(Macro, Core.NetworkClearText)

to the manifest and the log showed:


Not sure why it is not working for you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…